Decision Branching Error in matlab onramp

40 visualizzazioni (ultimi 30 giorni)
N/A
N/A il 2 Dic 2019
Commentato: AKANINYENE il 20 Ago 2025 alle 15:25
How to crack this error? The input data and solution provided by the matlab sources are same still the error is occuring.
  9 Commenti
prashant
prashant il 26 Ago 2024
When doPlot is 0, did you not plot the data?
prashant
prashant il 26 Ago 2024
Modify the script so that the plotting code on lines 5–8 execute only if doPlot is 1

Accedi per commentare.

Risposta accettata

Steven Lord
Steven Lord il 2 Dic 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.
  6 Commenti
AKANINYENE
AKANINYENE il 15 Ago 2025
is there no plot when doplot is 0?
Walter Roberson
Walter Roberson il 15 Ago 2025
The purpose of the doplot variable is to select whether plotting is to happen or not.

Accedi per commentare.

Più risposte (5)

Ivan Derkunskii
Ivan Derkunskii il 8 Mar 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 Commenti
Rahul Das A H
Rahul Das A H il 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
Walter Roberson il 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.

Accedi per commentare.


Bongani Tavengwa
Bongani Tavengwa il 4 Giu 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 Commenti
Steven Lord
Steven Lord il 4 Giu 2020
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?
AKANINYENE
AKANINYENE il 20 Ago 2025 alle 15:25
This suggested solution is not true

Accedi per commentare.


Sreekanth K M
Sreekanth K M il 17 Giu 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 Commenti
Wurood
Wurood il 23 Lug 2023
@ KRISTINA PAMELA RAMOS Thank you so much , finally it works

Accedi per commentare.


Surya Karthik Nadupalle
Surya Karthik Nadupalle il 22 Ago 2020
Modificato: Surya Karthik Nadupalle il 22 Ago 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 Commenti
Walter Roberson
Walter Roberson il 25 Giu 2021
We do not know what code you are using.
I also have not seen a copy of the question being asked.

Accedi per commentare.


1805645
1805645 il 20 Gen 2021
Hey, I have the same problem. How should I fix it?
  4 Commenti
Racha
Racha il 8 Dic 2023
Hi, I have also the same problem! What should I do ??
DGM
DGM il 8 Dic 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.

Accedi per commentare.

Tag

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by