[scilab-Users] basic operation but change in the matrix dimension

jasper van baten jasper at amsterchem.com
Fri Mar 12 11:08:34 CET 2010


Try to avoid looping over elements; use matrix operations instead. 
You never declared the size of Q. But you should be using

W_ =[3.717 ; 3.8535 ; 3.759 ; 3.801  ; 3.801 ]
S_ = 0.079
Q_=W_/S_

If you do need to loop, best to pre-declare Q

W_ =[3.717 ; 3.8535 ; 3.759 ; 3.801  ; 3.801 ]
Q_ = zeros(5,1)
[line_number,column_number] = size(W_)
S_ = 0.079
for i = 1 : line_number
   Q_(i) = W_(i) / S_ ;
end;
W_
Q_

or - in case you really want Q to be allocated on the fly, index properly:

W_ =[3.717 ; 3.8535 ; 3.759 ; 3.801  ; 3.801 ]
[line_number,column_number] = size(W_)
S_ = 0.079
for i = 1 : line_number
   Q_(i,1) = W_(i) / S_ ;
end;
W_
Q_

or Scilab will guess for you.

Best wishes,

Jasper.

At 11:00 3/12/2010, paul.carrico at free.fr wrote:
>Hi all,
>
>I'm doing the basic operation herebellow...
>W_ is a 5 x 1 matrix
>after calculation Q_ is a 1 x 5 matrix ==> why dimension has changed ????
>
>Slts
>
>PC
>
>
>##########################"
>W_ =[3.717 ; 3.8535 ; 3.759 ; 3.801  ; 3.801 ]
>[line_number,column_number] = size(W_)
>
>S_ = 0.079
>
>for i = 1 : line_number
>   Q_(i) = W_(i) / S_ ;
>end;
>
>W_
>Q_
>
>###########################
>result
>  W_  =
>
>     3.717
>     3.8535
>     3.759
>     3.801
>     3.801
>
>
>  Q_  =
>
>     47.050633    48.778481    47.582278    48.113924    48.113924




More information about the users mailing list