Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: Storing of values in an array
Posted:
Jan 26, 2014 10:21 AM


Ove R Take <noone@the.moment> wrote in message <lc0asu$l2r$1@news.abc.se>... > Narayanan skrev 20140125 07:37: > > > > But that is displaying the final value of SF1 and SF2. This is the code > > for SF1 where rad2 is a matrix and rows3 is the number of rows of matrix > > rad2. > > for c=1:(rows31) > > for d=2:rows3 > > if (dc)==1 angle=rad2(c,3)rad2(d,3); > > Vc=rad2(c,2); > > Vd=rad2(d,2); > > R=rad2(c,6); > > alpha=(R*cos(angle*pi/180))/(Vc*Vd); > > beta=(R*sin(angle*pi/180))/(Vc*Vd); > > Bus=rad2(c,1); > > SFrad2=(alpha*rad2(c,4)beta*rad2(c,5)); > > SF1=[rad2(c,1) SFrad2] > > % VS3= > > else > > end > > end > > This is the code for SF2 where rad3 is a matrix and rows4 is the number > > of rows of matrix rad3. > > for c=1:(rows41) > > for d=2:rows4 > > if (dc)==1 angle=rad3(c,3)rad3(d,3); > > Vc=rad3(c,2); > > Vd=rad3(d,2); > > R=rad3(c,6); > > alpha=(R*cos(angle*pi/180))/(Vc*Vd); > > beta=(R*sin(angle*pi/180))/(Vc*Vd); > > Bus=rad3(c,1); > > SFrad3=(alpha*rad3(c,4)beta*rad3(c,5)); > > SF2=[rad3(c,1) SFrad3] > > % VS4= > > else > > end > > end > > end > > > > Now I need to store all the values of SF1 and SF2 (i.e values generated > > in each iteration) in another array/matrix OV. Now can you help me? > > enddpb <none@non.net> wrote in message > > <lbttuv$ikt$1@speranza.aioe.org>... > >> On 1/24/2014 8:25 AM, dpb wrote: > >> ... > >> > >> > But, to answer the question > >> > > >> > OV=[SF1 SF2]; % SFx are row vectors > >> > > >> > or > >> > > >> > OV[SF1;SF2]; % they're columnoriented > >> > >> ERRATUM: > >> > >> Missing '=' sign, of course... > >> > >> OV=[SF1;SF2]; % they're columnoriented > >> > >> > >>  > > At the end of your loops you save only the result of the latest loop in > SF1 and SF2. You overwrite the result of the previous loop. Perhaps this > is what you want: > > ... > SF1 = [ SF1; rad2(c,1) SFrad2 ] > ... > SF2 = [ SF2; rad3(c,1) SFrad3 ] > ... > > This way you get two matrices SF1 and SF2 that may be appended: > > OV = [SF1;SF2] > > You may also have to "preallocate" SF*, using something like > > SF1=[]; > > or better  if you know their sizes  using something like > > SF1 = zeros(M,2);
Now as per the suggested idea I tried it but still the same problem persists. Where should I place this SF1 = [ SF1; rad2(c,1) SFrad2 ]? After the first or the second or outside of all the loops? The values are not getting appended but only the last value is getting stored.
Kindly help me.
Regards



