13.2 判定分岐 タスク2

if条件が満たされない場合にelseを使用するのですが,答えの通りに回答しても不正解になってしまいます.何が原因でしょうか.
if doPlot
plot(density)
title("Sample Densities")
ylabel("Density(g/cm^3)")
else
disp("The density of"+element ...
+"is"+density)
end

Answers (1)

Akiko
Akiko on 29 Jun 2022

0 votes

disp 内の string 配列で、正解の場合、よくみると of の後ろや is の前後に半角スペースがあります。
disp("The density of " + element ...
+ " is " + density)
すごくわかりづらいですよね。。。タスク内の disp... のコマンドをマウスで選択して Ctrl +C でコピーしてから貼り付けると確実と思います。
ちなみに、半角スペースがあると、出力結果が
"The density of Lithium is 0.53"
となりますが、前後のスペースがないと
"The density ofLithiumis0.53"
と表示されることになります。

Categories

Find more on MATLAB 入門 in Help Center and File Exchange

Products

Asked:

on 28 Jun 2022

Answered:

on 29 Jun 2022

Community Treasure Hunt

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

Start Hunting!