Info

この質問は閉じられています。 編集または回答するには再度開いてください。

can someone explain the error in this input for loop

3 ビュー (過去 30 日間)
Travis Heckler
Travis Heckler 2019 年 8 月 4 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Q0 = [];
for i=1:2
p = input(sprintf('Enter value for p(distance) [%d model]:',i));
v = input(sprintf('Enter value for v(velocity) [%d model]',i));
a = input(sprintf('Enter value for a(acceleration) [%d model]',i));
j = input(sprintf('Enter value for j(jerk)[%d model]',i));
Q0 = [Q0 ; p ; v ; a ; j ];
fprintf(Q0);
end
Enter value for p(distance) [1 model]:1
Enter value for v(velocity) [1 model]2
Enter value for a(acceleration) [1 model]3
Enter value for j(jerk)[1 model]4
Undefined function or variable 'Q0'.
I dont understand why its prompting me undefined variable.
  3 件のコメント
Travis Heckler
Travis Heckler 2019 年 8 月 4 日
No, it is Q0 both the places I dont know whats up with MATLAB
Travis Heckler
Travis Heckler 2019 年 8 月 4 日
Okay so I literally made no changes and it worked after a few desperate attempts to run it, I officially dont understand MATLAB

回答 (1 件)

Ajay Pattassery
Ajay Pattassery 2019 年 8 月 7 日
If you can see the issue again, revert with the error message and the code you have used. Also correct the usage of fprintf command in the above code. You need to specify the format of the output field. For example, if you are expecting integers use.
fprintf("%d",Q0);

この質問は閉じられています。

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by