Undefined function 'cos' for input arguments of type 'char'.
1 次查看(过去 30 天)
显示 更早的评论
Undefined function 'cos' for input arguments of type 'char'.
Error in EMF_Project (line 27)
Vg = ((Amp*cos(phi))+(1i*(Amp*sin(phi))));
I keep getting this error, if I remove the cos and sin it works fine but with them in it doesn't. Any thoughts on why?
prompt={'Enter The Generator Voltage Amplitude:','Enter Load Impedance:','Enter Characteristic Impedance:','Enter Length:','Enter The Generators Internal Impedance:','Enter Omega:','Enter The Reference Angle:'};
title='Please Provide the Information listed';
answer=inputdlg(prompt,title, [1 80]);
Amp = answer{1};
ZL = answer{2};
Zo = answer{3};
Length = answer{4};
Zg = answer{5};
w = answer{6};
phi = answer{7};
f = (w/(2*pi)); %calculating the frequency
Up = 3e8; %setting the phase velocity at the speed of light
Vg = ((Amp*cos(phi))+(1i*(Amp*sin(phi)))); %putting the generator voltage in the form of a complex # for later use.
lambda = (Up/f); %calculating the wavelength
0 个评论
采纳的回答
Sabin
2024-1-19
inputdlg returns a cell array of character vectors containing one input per edit field, starting from the top of the dialog box. Use the str2num function to convert space-delimited and comma-delimited values into row vectors, and semicolon-delimited values into column vectors. For an example, see Convert Input to Numeric Values.
Because phi is a character, function cos will then error out. By converting answer to numeric values should solve the problem:
Amp = str2num(answer{1});
...
phi = str2num(answer{7});
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!