Decision Branching Error in matlab onramp
Show older comments
How to crack this error? The input data and solution provided by the matlab sources are same still the error is occuring.

9 Comments
Sneham Shrikant Vaidya
on 16 May 2020
if doPlot
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
else
disp("The density of" + element + " is " + density)
end
// Just paste the following code or simply remove dashed line infront of solution in else statement
Heena Singh
on 19 May 2020
i have tried this too, but still its not working!
shubham kumar
on 11 Jun 2020
how to do
Walter Roberson
on 13 Jul 2020
disp("The density of " + element + " is " + density)
Notice the space needed after "of"
Venkateshan Shanmugam
on 25 Jun 2021
I tried using the same . But still the same error
Venkateshan Shanmugam
on 26 Jun 2021
I got the solution just Enclose
if (doplot == 1)
Mahmoud
on 1 May 2024
still have the same problem
prashant
on 26 Aug 2024
When doPlot is 0, did you not plot the data?
prashant
on 26 Aug 2024
Modify the script so that the plotting code on lines 5–8 execute only if doPlot is 1
Accepted Answer
More Answers (5)
Ivan Derkunskii
on 8 Mar 2020
5 votes
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 Comments
Abdul Rehman
on 7 Apr 2020
Yes! it really worked.
Saurabh Shah
on 21 Apr 2020
Why is it so that after giving sapce it cosidered the code valid ?
Steven Lord
on 21 Apr 2020
Adding or removing spaces can change the meaning of a word or phrase.
"I'm Popeye The Sailor Man" is somewhat different from "I'm Popeye The Sail or Man". In the former, Popeye is a man who sails. In the latter, Popeye could be a man or could be part of a ship.
If you were asked to name the theme song for the cartoon character, the former would be marked correct but the latter would not.
Rasim Tawfeeq
on 1 Jun 2020
I've also tried this, but it still does not work!
There is no skipping at this point!
shubham kumar
on 11 Jun 2020
how to crack this tried a lot
Rupesh Shrestha
on 4 Aug 2020
HAHAHAHAHA Exactly!!!!
I tried putting spaces too but I had missed one space. Then again I tried with spaces in all places, it finally works.
if doPlot
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
else
disp(" The density of " + element ...
+ " is " + density)
end
Rahul Das A H
on 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
on 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
on 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
4 Comments
Bongani Tavengwa
on 4 Jun 2020
where did i go wrong ?????
Bongani Tavengwa
on 4 Jun 2020
please do stage by stage when giving answer
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?
AKANINYENE
on 20 Aug 2025
This suggested solution is not true
Sreekanth K M
on 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 Comments
Milagros Walker
on 24 Sep 2020
still stuck in here
Steven Lord
on 24 Sep 2020
Without seeing what you tried we can't determine why what you tried isn't working.
Venkateshan Shanmugam
on 25 Jun 2021

I tried all the Solutions still the same error
KRISTINA PAMELA RAMOS
on 19 Jul 2021
delete/remove lines 5-8
start with if doPlot == 1 and so on
it will work
Ashutosh Pal
on 12 Apr 2022
It worked. Thanks
Wurood
on 23 Jul 2023
Surya Karthik Nadupalle
on 22 Aug 2020
Edited: Surya Karthik Nadupalle
on 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 Comments
Milagros Walker
on 24 Sep 2020
still di not work
Venkateshan Shanmugam
on 24 Jun 2021
Still Did not work
Walter Roberson
on 25 Jun 2021
We do not know what code you are using.
I also have not seen a copy of the question being asked.
1805645
on 20 Jan 2021
0 votes
Hey, I have the same problem. How should I fix it?

5 Comments
Attilio Pallage Don
on 12 Mar 2021
just clear the default code in task 1&2, then try the code......!!!!!!
Walter Roberson
on 25 Jun 2021
You have plot(density) left over from Task 1 & 2. You are required to modify the code so that that plot() does not occur if doPlot is not 1.
Racha
on 8 Dec 2023
Hi, I have also the same problem! What should I do ??
DGM
on 8 Dec 2023
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.
AKANINYENE
on 19 Sep 2025
How do I modify the code
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!