"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <geigjc$k7b$1@fred.mathworks.com>...
> "rose lans" <byrusel42@yahoo.com> wrote in message <gei7ma$id6$1@fred.mathworks.com>...
> > Hi,
> > I am a beginner to MATLAB, so i am sorry if my question is way too trivial.
> > I am working on a program where I have to plot two variables, N and t:
> > function [t, N]=vloop (N,S,O)
> >
> > i=1;
> > for i1=1:length (N)
> > Ne=N (i1);
> > for i2=1:length (S)
> > Sal=S (i2);
> > for i4=1:length (O)
> > OvH=O(i4);
> > [ X, r, Y,e]=F(3, 30, Ne) ;
> > Nov=(X+Y);
> > total=total_cost (Ne,S,Nov,O);
> > N (i)=Ne;
> > Salv (i)=Sal;
> > OvHv (i)=OvH;
> > i=i+1;
> >
> > end
> > end
> > end
> >
> > F and total_cost are separate functions in separate mfiles. I am using their output to get total (I hope that makes sense).
> > The program runs, but when I try to plot total vs. N, I get
> > ??? Error using ==> plot
> > Vectors must be the same lengths.
> > How can I fix that?
> > Thank you.
>
> Hi,
> There are several weak points in your code:
> 1. If you like to plot results outside the function vloop, the output argument t should be assigned some values, it means it should be indexed inside the most inner loop.
> 2. The code is dangerous , because the input variable N is overwritten inside the inner loop. More over, the length of N will increase over the original length. Better would be to use different name of the output argument.
> 3. There are variables Salv and OvHv which are not used. More over their dimension is increasing, what means that computing time will be very long. To inprove it, you should declare them before the outer loop by assigning them, say
> Salv=zeros(1,length(N)*length(S)*length(O));
> Hope it helps.
> Mira
>
Thank you for a quick reply,
It does help, I just got confused in syntax.
