Problem over switch function
Mostra commenti meno recenti
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).
1 Commento
Joel
il 22 Set 2014
Risposta accettata
Più risposte (2)
Guillaume
il 22 Set 2014
1 voto
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.
1 Commento
Joel
il 22 Set 2014
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 Commenti
Shammi Doly
il 9 Gen 2020
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
il 9 Gen 2020
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.
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!