Date: Feb 3, 2013 11:04 AM
Author: dpb
Subject: Re: Problem using plots and loops

On 2/3/2013 1:06 AM, Ankita wrote:

> 1) In the first 2 if loops, I want to make sure that the ratio fits in a
> given limit. Is there any better way of doing that?

You could write things like Nmax=min(InputRatio,Limit) etc., but if it
works as is, that's a nicety and since it's just a single set of values
and is in an user input section the time isn't an issue...I'd let it go
until got other things worked out and develop some more familiarity w/
Matlab and programming in general...

> 2) When I execute
> the program, only the fprintf in 2nd if loop is executed. Why is that?

Would seem to be owing to the values you've selected -- altho it's
possible you've written a set of conditions such that one branch can
never be reached because the tests aren't possible--I didn't have time
at the moment to read it that carefully, sorry...

> 3) For the last for loop, I should be get 4 different curves for 4
> values of N. Instead I get one curve (the curve is actually a set of
> points. Not a continuous line. That too is my problem.)

Compute the points in an array and then plot each line when you have a
set of values for the curve instead of each point as it is calculated.


> B=M_f+N_f;
> if M_f/B<0.20
> if M_f/B>0.1
> Nmax=W*(M_f/B);
> else
> Nmax=W*0.15; %max static load per nose wheel
> fprintf('The M_f/B ratio ...
> end
> end
> if M_a/B>0.05
> if M_a/B<0.1
> Nmin=W*(M_f/B);
> else
> Nmin=W*0.08; %min static load per nose wheel
> fprintf('The M_a/B ratio has ...
> end
> end


> %hold on;
> K=L/W;

for N=1.5:0.5:3
hold on

Above computes the S vector for each point in the V vector w/o a loop
then plots it.

You'll probably want to add a color value to the plot since the colors
won't automagically cycle unless S is a column vector. Or, you could
create a 2D array and save the whole thing then plot since the sizes are
quite small...

S=zeros(length(V)),4); % preallocate
for N=1.5:0.5:3
i = i+1; % array column index

And, of course, one could look at

doc meshgrid

to do the computation w/o any explicit loops at all...