Problem over switch function
이전 댓글 표시
So this is what I have so far.

and here is the problem:

I've made the switches, and when I go to HELP SWITCH, it shows me how to do the switch, but I don't really understand how to integrate it within the problem. I was trying to figure out if there was a way to input the element needed, and then it would add the values of a and b, and then I could execute the equation, but I can't really figure out how to go about doing that (if I'm right).
채택된 답변
추가 답변 (2개)
Guillaume
2014년 9월 22일
1 개 추천
Please don't post images of code when you could just copy and paste the code.
Your switch syntax is correct. However, for it to be useful, you need to put it before the equation not after.
If you'd copy-pasted the code, I would have copied it below and rearranged it for you. Can't do that with a picture.
Hi,
you have to write a function:
function P = VanDerWaals(T,V,e)
% switch-case
% computation of P
Since R is the same for every gas you can enter the value directly in the equation.
댓글 수: 2
Shammi Doly
2020년 1월 9일
hi,
I am trying to read data from the RADAR sensor through the USB port. I used switch function to read the real time data. But I am getting some error like this.'Not enough input arguments.Error in f_serial (line 2).
function p = f_serial(p,str)
switch(str)
case 'clear'
a = instrfindall();
if(isempty(a)==0)
fclose(a);
delete(a);
end
case 'openBGT'
try
p.sr = serial(p.serialPortBGT,'BAUD',9600);
set(p.sr,'Timeout',0.5);
set(p.sr,'InputBufferSize',8192);
fopen(p.sr);
catch
disp('Error while opening USB Connection. Check the connection or the portname');
return
end
case 'closeBGT'
fclose(p.sr);
delete(p.sr);
end
Steven Lord
2020년 1월 9일
That suggests you called f_serial with only one input. If you did, when MATLAB tries to evaluate the switch expression str is undefined. MATLAB can see that str was defined to be an input argument to your function and so gives you a (hopefully) more informative error, that you called your function with fewer inputs than your function requires.
Call your function with the two inputs that it requires.
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!