program behavior due to editor issues

1 view (last 30 days)
Fred
Fred on 5 Oct 2013
Commented: cr on 5 Oct 2013
In the attached code adding the two line commands near the top changes the behavior of the program from how it behaved without the line commands. Then I comment out the line commands and the program behavior does not revert to the program without the line commands. I delete the line commands and the program does not revert to the original.
Very confusing.
I have noticed other strange behavior. My code wasn't working as expected. I removed a section of code that looked correct, just to try something. I reinserted the very same section and the program worked as expected. I performed these operations with control x and control v.
I hope I am doing something wrong.
%Molecule trajectory
clf
xx=1:10;z=[1 0 0 0 0 0 0 0 1 0];stem(xx,z)
axis ([0 10 0 2]);
%line([1,4],[1,1])
%line([6,9],[1,1])
hold on
x = 0; y = 0;
plot(9.5,1.2, 'o')
dx = .1; dy = .008; N = 200;
xo = 8.5; yo = 1.5;
for i = 1:N
x(i) = xo - i*dx;
y(i) = yo - i*dy;
plot(x(i),y(i))
if x(i)<=1
plot(x(i),y(i),'o')
%set(p,'Color','red','LineWidth',1)
%line([xo,yo],[x(i),y(i)])
%return
break
end
end
x1 = x(i)
y1 = y(i)
i = 0;
for i = 1:N
x(i) = x1 + i*dx;
y(i) = y1 - i*dy;
plot(x(i),y(i))
if y(i)<=0
plot(x(i),y(i),'o')
%set(p,'Color','red','LineWidth',1)
%line([xo,yo],[x(i),y(i)])
%return
break
end
end
x1 = x(i)
y1 = y(i)
i = 0;
for i = 1:N
x(i) = x1 + i*dx;
y(i) = y1 + i*dy;
plot(x(i),y(i))
if x(i)>=9
plot(x(i),y(i),'o')
%set(p,'Color','red','LineWidth',1)
%line([xo,yo],[x(i),y(i)])
%return
break
end
end
x1 = x(i)
y1 = y(i)
i = 0;
for i = 1:N
x(i) = x1 - i*dx;
y(i) = y1 + i*dy;
plot(x(i),y(i))
if x(i) <= 1
plot(x(i),y(i),'o')
%set(p,'Color','red','LineWidth',1)
%line([xo,yo],[x(i),y(i)])
%return
break
end
end
x1 = x(i)
y1 = y(i)
i = 0;
for i = 1:N
x(i) = x1 + i*dx;
y(i) = y1 + i*dy;
plot(x(i),y(i))
if x(i) >= 9.5
plot(x(i),y(i),'o')
%set(p,'Color','red','LineWidth',1)
%line([xo,yo],[x(i),y(i)])
%return
break
end
end
  1 Comment
cr
cr on 5 Oct 2013
Unable to reproduce your issue. For me, "lines" just create two additional horizontal lines and dont change anything else either in the plot or x1,y1 in command window. Is this a script or a function? If a function make sure your function name and filename are the same to avoid confusing outputs. Create a fresh directory and use scripts if functions dont have any i/o.

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!