필터 지우기
필터 지우기

Matlabonramp 13.2.

조회 수: 16 (최근 30일)
Rola Helwa
Rola Helwa 2020년 9월 22일
답변: Vikas Chelluru 2022년 7월 12일
The elseif keyword can be used after if to add more conditions. You can include multiple elseif blocks.
Try adding a variable doDisplay to toggle if the densities are displayed. Add this condition with an elseif block.
I don't really understand or know what to write and what the task wants. What does mean "to toggle" here mean?
This is the furhther practice from the Matlab Onramp course chapter 13

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 9월 22일
"Toggle" means to switch between to states (on/off, yes/no, in/out, show/hide, etc).
A Further Practice section is an area to practice what you have learned. Here, you are provided with a suggestion of what you could do. The suggestion is to replace "else" with "elseif". This creates the opportunity to test a second condition, doDisplay. Follow the same steps you used to create the first condition, doPlot.
  댓글 수: 5
Cris LaPierre
Cris LaPierre 2021년 6월 4일
Yes, you will have to create it first (similar to what you did with doPlot) before you can use it in an elseif statement.
Thiago carneiro
Thiago carneiro 2021년 6월 13일
@Ahilan R it is almost the correct answer. but you are using the matrix notation,i think you must use only a range of integer like do plot. randi[(0 1]). in this case, doDisplay will be toggle only when doPlot==0 and doDisplay==1. All other situations doDisplay will not pop up. I am wrong, somebody correct me, i am a new user.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Merel Cook
Merel Cook 2020년 11월 12일
Now help with 13.2. I am receiving the error code, "are densities displayed when doPlot is 0". What does this error code mean?
  댓글 수: 4
JAT
JAT 2020년 11월 17일
편집: JAT 2020년 11월 17일
Cris, is there a place we can suggest the tutorial question be reworded for clarification? I didn't understand what the task required either, and from a Google search there are others in the same position. It's been a very clear and understandle onramp tutorial so far - just struggling with this part. Thank you
Cris LaPierre
Cris LaPierre 2020년 11월 17일
At the top right of the course, there is a question mark icon. Click on that and select "Contact Support".
From there you can create a service request, which allows you to provide suggestions back to MathWorks. Anything you put there will get to the course creator for their consideration. Be sure to be specific on what is causing the confusion.
Remember that for Tasks you can always click "See Solution". Once you understand what the solution is, it would be great if you could share what better wording might be, or what had led you to interpret the question differently than what was intended.

댓글을 달려면 로그인하십시오.


Mohammad Ali
Mohammad Ali 2021년 6월 5일
if doPlot == 1
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
elseif doDisplay == 1
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
else
disp("The density of " + element ...
+ " is " + density)
end

Vikas Chelluru
Vikas Chelluru 2022년 7월 12일
doPlot = randi([0 1])
doDisplay=randi([0 1]
load datafile
density = data(:,1)
if doPlot == 1
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
elseif doDisplay ==1
disp("The density of "+ element+ " is " + density)
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by