フィルターのクリア

Disp() not showing the value of the variable

43 ビュー (過去 30 日間)
Daniel Gollin
Daniel Gollin 2020 年 7 月 15 日
回答済み: Abhishek Gangwar 2020 年 7 月 15 日
I am trying to at the end of a program have it display the # of jumbles solved and # of jumbles attempted.
I have it set up as
a=['# jumbles attempted: ',attempts];
s=['# jumbles solved: ',words_solved];
disp(a)
disp(s)
attempts and words_solved are variables that are previously defined within the script.
In a scenario where at the time this part of the code runs attempts = 1 and words_solved = 0, I am receiving this output
(# jumbles attempted: .)
(# jumbles solved: .) (output doesn't actually show these parenthesis)
I'm not sure why the values aren't displaying as I have a disp() earlier in my program set up in the exact same structure that works fine.
For reference (this one works how it is supposed to):
x = ['The word was ',correctWord,'.'];
disp(x) %displays the original word

採用された回答

Abhishek Gangwar
Abhishek Gangwar 2020 年 7 月 15 日
The reason is, one of your argument is a decimal number and the other one is a string, try to convert decimal number into string using 'num2str()' function and then print it, it will work fine.
For example, do a=['# jumbles attempted: ',num2str(attempts)];
Alternatively you can use other matlab function to print a formatted string as an output,
For exapmle you can do disp(sprintf('# jumbles attempted %d', attempts));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by