Hi, I'm trying to find a program line which will make matlab dump numbers that don't respond to an if statement.

1 visualización (últimos 30 días)
if abs(z(1,end,n)-Z)<=Err
hold on
figure(1)
plot(z(1,:),z(3,:))
xlabel('x')
ylabel('y')
axis ([0 12000 0 10000])
else
%Dump, don't plot.
  3 comentarios
Christopher
Christopher el 30 de Nov. de 2012
I want simply to stop it from plotting everything, i'll post the code so you can run it.
function [ ] = lolly()
tInc = input('Input desired timestep (in seconds)');
Z = input('Input desired Landing distance (in meters)');
t(1)=0;
Ang1 = input('First angle of shooting (in degrees)');
Ang2 = input('Last angle of shooting (in degrees)');
AInc = input('Angle increment (also in degrees)');
Err = input('Acceptable Error (in meters)');
w = (Ang2-Ang1)/AInc;
IAng = linspace(Ang1,Ang2,w);
for n=1:w;
z(:,1,n) = VelocityforAngle(IAng(n));
i=1;
while z(3,i,n)>=0;
i=i+1;
t(i)=t(i-1)+tInc;
[z(:,i,n)] = oneStepRK(t(i-1), z(:,i-1,n), tInc);
if abs(z(1,end,n)-Z)<=Err
hold on
figure(1)
plot(z(1,:),z(3,:))
xlabel('x')
ylabel('y')
axis ([0 12000 0 10000])
else
end
end
end
Walter Roberson
Walter Roberson el 30 de Nov. de 2012
Editada: Walter Roberson el 30 de Nov. de 2012
You want it to stop all further plots? Or you want it to continue on with the next "n" ? Or you just don't want to plot that one line?
The code you already give will have it skip one line.
Earlier on you assign to z(:,i,n) but in that if you refer to z(1,end,n) which seems to rely upon the fact that you did not pre-allocate z and so "end" refers to the same location as "i". Why not just code as "i", z(1,i,n) and avoid the confusion ?
Why are you referring to z in 3 dimensional form as you calculate it, but in 2 dimensional form when you plot it?

Iniciar sesión para comentar.

Respuestas (1)

dpb
dpb el 1 de Dic. de 2012
If you want to abort the loop see
doc break
If you want to keep going then as Walter notes the empty ELSE clause skips effectively (of course you can just use an IF...END w/o the ELSE too)...
If it's something else, the description isn't terribly precise...

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by