필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Anuradha Bhattacharya
Anuradha Bhattacharya 2016년 5월 23일
댓글: Walter Roberson 2016년 5월 23일
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.
Walter Roberson
Walter Roberson 2016년 5월 23일
By the way you probably want \n not /n

댓글을 달려면 로그인하십시오.

답변 (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