Decision Branching Error in matlab onramp

조회 수: 37 (최근 30일)
N/A
N/A 2019년 12월 2일
댓글: prashant 2024년 8월 26일
How to crack this error? The input data and solution provided by the matlab sources are same still the error is occuring.
  댓글 수: 9
prashant
prashant 2024년 8월 26일
When doPlot is 0, did you not plot the data?
prashant
prashant 2024년 8월 26일
Modify the script so that the plotting code on lines 5–8 execute only if doPlot is 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

댓글을 달려면 로그인하십시오.

추가 답변 (5개)

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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by