Decision Branching Error in matlab onramp

How to crack this error? The input data and solution provided by the matlab sources are same still the error is occuring.

9 Comments

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
i have tried this too, but still its not working!
disp("The density of " + element + " is " + density)
Notice the space needed after "of"
I tried using the same . But still the same error
I got the solution just Enclose
if (doplot == 1)
still have the same problem
When doPlot is 0, did you not plot the data?
Modify the script so that the plotting code on lines 5–8 execute only if doPlot is 1

Sign in to comment.

 Accepted Answer

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.

6 Comments

N/A
N/A on 2 Dec 2019
Edited: N/A on 28 Dec 2020
yes, got the solution. Thank you.
Hello Girish
Please share the solution for this code.
As i'm currently stuck at this stage.
Thanks
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.
Hi Steve
Thanks for the quick response.
Even after following the phrase is still saying incorrect.
thanks.
Capture.PNG
is there no plot when doplot is 0?
The purpose of the doplot variable is to select whether plotting is to happen or not.

Sign in to comment.

More Answers (5)

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

Yes! it really worked.
Why is it so that after giving sapce it cosidered the code valid ?
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.
I've also tried this, but it still does not work!
There is no skipping at this point!
how to crack this tried a lot
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
load datafile
density = data(:,1);
if doPlot == 1
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
end
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.

Sign in to comment.

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

where did i go wrong ?????
please do stage by stage when giving answer
name = "Bongani Tavengwa";
disp("Do you see the problem now" + name)
Do you see the problem nowBongani Tavengwa
disp("Do you see the problem now " + name)
Do you see the problem now Bongani Tavengwa
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?
This suggested solution is not true

Sign in to comment.

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

still stuck in here
Without seeing what you tried we can't determine why what you tried isn't working.
I tried all the Solutions still the same error
delete/remove lines 5-8
start with if doPlot == 1 and so on
it will work
It worked. Thanks
@ KRISTINA PAMELA RAMOS Thank you so much , finally it works

Sign in to comment.

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

We do not know what code you are using.
I also have not seen a copy of the question being asked.

Sign in to comment.

1805645
1805645 on 20 Jan 2021
Hey, I have the same problem. How should I fix it?

5 Comments

just clear the default code in task 1&2, then try the code......!!!!!!
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.
Hi, I have also the same problem! What should I do ??
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.
How do I modify the code

Sign in to comment.

Products

Release

R2019b

Tags

Asked:

N/A
on 2 Dec 2019

Commented:

on 19 Sep 2025

Community Treasure Hunt

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

Start Hunting!