Error using sprintf command

sprintf('Iteration: %d, Sum: %d, difference: %d',a, SUMSED(a,1), diff_(a,1))
The system cannot find the path specified.
Unrecognized function or variable 'SUMSED'.

7 件のコメント

KSSV
KSSV 2021 年 9 月 21 日
Use fprintf.
The error is clear, SUMSED is not defined.
Walter Roberson
Walter Roberson 2021 年 9 月 21 日
sprintf() is fine in this context.
If you have any "if" statements, then it possible that none of them came out true. That can especially happen if you accidentally test an entire vector instead of one element of the vector.
Nitesh Kumar Singh
Nitesh Kumar Singh 2021 年 9 月 21 日
編集済み: Walter Roberson 2021 年 9 月 21 日
% 6. Convergence control
% SUMMATION OF SED PER ITERATION
Q(a,1) = 0;
for i = 1:N_ele
Q(a,1) = sed(i,a)+Q(a,1);
end
% CALCULATION OF DIFFERENCE OF SED OF
% TWO FOLLOWING ITERATIONS
if (a>1)
q_dot(a,1) = abs(Q(a,1) - Q(a-1,1));
else
q_dot(a,1) = 0;
end
% OUTPUT
sprintf('Iteration: %d, Sum: %d, difference: %d',a, SUMSED(a,1), diff_(a,1))
1. Error is still coming after using fprintf. @KSSV
2. i am not using any "if" statement here but all the code is working in "for loop". @Walter Roberson
Walter Roberson
Walter Roberson 2021 年 9 月 21 日
You do not assign to SUMSED anywhere in that code.
However, your variable Q appears to be a total (sum) of sed values.
KSSV
KSSV 2021 年 9 月 21 日
It seems Q is SUMSED.
Image Analyst
Image Analyst 2021 年 9 月 21 日
Why are you not using the sum(), cumsum(), and diff() functions to do this?
Nitesh Kumar Singh
Nitesh Kumar Singh 2021 年 9 月 22 日
i have change sumsed to Q and diff_ to q_dot and its working well.
Actually sir i am studying a someon else's code @Image Analyst.

サインインしてコメントする。

回答 (0 件)

タグ

質問済み:

2021 年 9 月 21 日

コメント済み:

2021 年 9 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by