MATLAB: Toggle and elseif in matlab

decision branchingelseiftoggle

Try adding a variable doDisplay to toggle if the densities are displayed. Add this condition with an elseif block.
i do not understand what we are supposed to do in the above question(bold). this question is a part of futher practice in mathlab oramp. decision branching topic futher practice section in matworks course for basic matlab. how do i solve tha bove question

Best Answer

Shivaani - I think that all the code is asking you to do is to add another variable called doDisplay and an elseif that would check if this variable is true. If so, then you would plot the densities. So there would be two ways to plot the data - either through the doPlot or with the doDisplay
if doPlot
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
elseif doDisplay
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
else
disp("The density of " + element ...
+ " is " + density)
end
You would need to declare and initialize the doDisplay variable too.