필터 지우기
필터 지우기

two inputs and two equations

조회 수: 1 (최근 30일)
Aleksandra Ksiezyk
Aleksandra Ksiezyk 2020년 2월 4일
댓글: Aleksandra Ksiezyk 2020년 2월 5일
hey !
is there a way to write a script/funtion/loop that understand i have two inputs (one is set and the second reminds "empty") and two equations with the same output, take the right equation and calculate my output ? eg
i have two possible inputs: Hp and Hkom
equations:
V = 12 + 3.2*Hp
or
V = 12 + 4*Hkom
i want matlab to understand that if i set one input Hp = 12 the second imput Hkom should be neclacted and take the write equation: V = 12 + 3.2*Hp
and calculate my V ??
  댓글 수: 3
Aleksandra Ksiezyk
Aleksandra Ksiezyk 2020년 2월 4일
no, i did not try because i want to avoid case or if. that is why i wrote here if anyone has some idea to solve it.
John D'Errico
John D'Errico 2020년 2월 4일
As I pointed out, you still really do need to use an if, in some form.

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

채택된 답변

John D'Errico
John D'Errico 2020년 2월 4일
This is easy enough to answer, as long as EXACTLY ONE of the two inputs was provided.
However, you need to consider what happens if BOTH or NEITHER of the values were provided. In those cases, your code would fail. It must fail, because an incomplete definition was given.
What code would I write to solve this? Simplest might be:
if numel([Hp,Hkom]) ~= 1
error('The sky is falling!')
else
V = [12 + 3.2*Hp,12 + 4*Hkom];
end
  댓글 수: 1
Aleksandra Ksiezyk
Aleksandra Ksiezyk 2020년 2월 5일
it does not work at all. :(
it i assign Hp = 6 and Hkom=2 it does not work and when i write only one variables .
Hp= 6;
Hkom=2;
if numel([Hp,Hkom]) ~= 1
error('The sky is falling!')
else
V = [12 + 3.2*Hp,12 + 4*Hkom];
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by