Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Storing of values in an array
Replies: 7   Last Post: Jan 30, 2014 8:44 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Narayanan

Posts: 14
Registered: 6/10/13
Re: Storing of values in an array
Posted: Jan 26, 2014 10:21 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Ove R Take <noone@the.moment> wrote in message <lc0asu$l2r$1@news.abc.se>...
> Narayanan skrev 2014-01-25 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:(rows3-1)
> > for d=2:rows3
> > if (d-c)==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:(rows4-1)
> > for d=2:rows4
> > if (d-c)==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 column-oriented

> >>
> >> ERRATUM:
> >>
> >> Missing '=' sign, of course...
> >>
> >> OV=[SF1;SF2]; % they're column-oriented
> >>
> >>
> >> --

>
> 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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.