Decision Branching Error in matlab onramp
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How to crack this error? The input data and solution provided by the matlab sources are same still the error is occuring.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/251819/image.jpeg)
7 Kommentare
Akzeptierte Antwort
Steven Lord
am 2 Dez. 2019
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 Kommentare
Steven Lord
am 17 Dez. 2019
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
am 18 Dez. 2019
Hi Steve
Thanks for the quick response.
Even after following the phrase is still saying incorrect.
thanks.
![Capture.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/254966/Capture.png)
Weitere Antworten (7)
Ivan Derkunskii
am 8 Mär. 2020
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 Kommentare
Rahul Das A H
am 5 Feb. 2022
load datafile
density = data(:,1);
if doPlot == 1
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
end
Walter Roberson
am 5 Feb. 2022
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
am 4 Jun. 2020
if doPlot
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
else
disp("The density of" + element + "is" + density)
end
3 Kommentare
Steven Lord
am 4 Jun. 2020
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
am 17 Jun. 2020
if doPlot
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
else
disp(" The density of " + element + " is " + density)
end
6 Kommentare
Surya Karthik Nadupalle
am 22 Aug. 2020
Bearbeitet: Surya Karthik Nadupalle
am 22 Aug. 2020
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 Kommentare
Walter Roberson
am 25 Jun. 2021
We do not know what code you are using.
I also have not seen a copy of the question being asked.
梦波
am 22 Aug. 2023
It's not a logical error, but a format error. You need add spaces in the double quotes
0 Kommentare
Al
am 8 Feb. 2024
If you find error, follow these instructions
- First of all, refresh the editor (or close all tab and resume the course)
- 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!