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

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 Comments

It may not be showing because they might not be obeying your condition DY>2000 && VALUE<1.
Are you able to upload a sample data file that will allow us to run the code and see the error for ourselves?
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.
By the way you probably want \n not /n

Sign in to comment.

Answers (0)

Tags

Asked:

on 23 May 2016

Commented:

on 23 May 2016

Community Treasure Hunt

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

Start Hunting!