I am getting a bug in my code using fprintf, can someone tell me why?

1 次查看(过去 30 天)
This is my code:
a = load('xaxisfig7line1');
x = a(:,2);
y = a(:,1);
dy = diff(y)./diff(x);
b = [0];
dy = vertcat(b,dy);
X = horzcat(x,dy);
Y = horzcat(y,dy);
for i = 1:6614;
DY = abs(dy((i+1),1)-dy((i),1));
VALUE = abs(dy(i,1));
if DY>2000 & VALUE<1
fprintf('%f/n',x(i))
fprintf('%f/n',y(i))
else
end
end
The error I get is the printed numbers are showing DY and VALUE. Why is it not showing me x(i) and y(i)? Thanks...
  4 个评论
dpb
dpb 2016-5-23
I'm sorry, but the assertion "the printed numbers are showing DY and VALUE" is simply NOT so if the code actually being run is what is shown. Whatever value is being displayed by fprintf is the value of x, y at that time; that is definite. Now, those may not be what you think they should be, but Matlab isn't going to substitute some other value in their place. Use the debugger and see where things depart from your expectations.
A possibility is that as the earlier poster noted perhaps your if statement isn't being satisfied and you're not using the identical code as above and what you're actually seeing is the result of the lines defining DY and VALUE missing the trailing semi-colon. Something along these lines would be my best reading of the crystal ball...as the other responder noted, we can't see your terminal so with out a sample of the input data and the corresponding output it's all supposition.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by