Decision Branching Error in matlab onramp

42 ビュー (過去 30 日間)
N/A
N/A 2019 年 12 月 2 日
回答済み: Al 2024 年 2 月 8 日
How to crack this error? The input data and solution provided by the matlab sources are same still the error is occuring.
  6 件のコメント
Venkateshan Shanmugam
Venkateshan Shanmugam 2021 年 6 月 25 日
I tried using the same . But still the same error
Venkateshan Shanmugam
Venkateshan Shanmugam 2021 年 6 月 26 日
I got the solution just Enclose
if (doplot == 1)

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

採用された回答

Steven Lord
Steven Lord 2019 年 12 月 2 日
That might be checking that the densities that are printed as text when doPlot is 0 exactly match the densities that would be printed by "the code as shown above". The code you're using doesn't exactly match: note that your code doesn't display a space between "of" and the name of the element. Try adding the spacing before and after the element name (as I believe "the code as shown above" does) and see if that allows you to pass the test case.
  4 件のコメント
Steven Lord
Steven Lord 2019 年 12 月 17 日
Compare:
x = 1;
y = 2;
disp("The value of x is" + x + "and the value of y is" + y)
disp("The value of x is " + x + " and the value of y is " + y)
The two phrases displayed are not identical. If your code displayed the first of those phrases but the exercise expected the second your code would not pass the test.
Damilola Adeniji
Damilola Adeniji 2019 年 12 月 18 日
Hi Steve
Thanks for the quick response.
Even after following the phrase is still saying incorrect.
thanks.
Capture.PNG

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

その他の回答 (7 件)

Ivan Derkunskii
Ivan Derkunskii 2020 年 3 月 8 日
You'll be laughing, but you need just put spaces inside the phrases "The density of the" and "is" so that they look like "The density of the " (a space after the whole phrase) and " is " (spaces before and after the word).
  8 件のコメント
Rahul Das A H
Rahul Das A H 2022 年 2 月 5 日
load datafile
density = data(:,1);
if doPlot == 1
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
end
Walter Roberson
Walter Roberson 2022 年 2 月 5 日
Comparing to 1 is not necessary in the case where the values are guaranteed to be either 0 or 1.
In the case where the values are not guaranteed to be one of those two, then you need to know whether the rule is that the number must be exactly 1 to pass, or if the rule is that the number must not be zero to pass.

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


Bongani Tavengwa
Bongani Tavengwa 2020 年 6 月 4 日
if doPlot
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
else
disp("The density of" + element + "is" + density)
end
  3 件のコメント
Bongani Tavengwa
Bongani Tavengwa 2020 年 6 月 4 日
please do stage by stage when giving answer
Steven Lord
Steven Lord 2020 年 6 月 4 日
name = "Bongani Tavengwa";
disp("Do you see the problem now" + name)
disp("Do you see the problem now " + name)
Do you see the difference in the two displayed statements? What's the difference between the second and third lines of code and what impact does that difference have in the displayed text?

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


Sreekanth K M
Sreekanth K M 2020 年 6 月 17 日
if doPlot
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
else
disp(" The density of " + element + " is " + density)
end
  6 件のコメント
Ashutosh Pal
Ashutosh Pal 2022 年 4 月 12 日
It worked. Thanks
Wurood
Wurood 2023 年 7 月 23 日
@ KRISTINA PAMELA RAMOS Thank you so much , finally it works

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


Surya Karthik Nadupalle
Surya Karthik Nadupalle 2020 年 8 月 22 日
編集済み: Surya Karthik Nadupalle 2020 年 8 月 22 日
The problem is solved only when you give gaps between words in the bracket. Notice the spacing i gave. It worked
disp(" The density of " + element + " is " + density)
  3 件のコメント
Venkateshan Shanmugam
Venkateshan Shanmugam 2021 年 6 月 24 日
Still Did not work
Walter Roberson
Walter Roberson 2021 年 6 月 25 日
We do not know what code you are using.
I also have not seen a copy of the question being asked.

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


1805645
1805645 2021 年 1 月 20 日
Hey, I have the same problem. How should I fix it?
  4 件のコメント
Racha
Racha 2023 年 12 月 8 日
Hi, I have also the same problem! What should I do ??
DGM
DGM 2023 年 12 月 8 日
If you have the same problem, then Walter already gave the answer. If you have a different problem, nobody can possibly know what it is unless you describe it.

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


梦波
梦波 2023 年 8 月 22 日
It's not a logical error, but a format error. You need add spaces in the double quotes

Al
Al 2024 年 2 月 8 日
If you find error, follow these instructions
  1. First of all, refresh the editor (or close all tab and resume the course)
  2. Then copy the following code
if doPlot == 1
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
else
disp("The density of"+element+"is"+density)
end
3. Now submit the task

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by