Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Anuradha Bhattacharya
Anuradha Bhattacharya le 23 Mai 2016
Commenté : Walter Roberson le 23 Mai 2016
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 commentaires
dpb
dpb le 23 Mai 2016
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.
Walter Roberson
Walter Roberson le 23 Mai 2016
By the way you probably want \n not /n

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by