Undefined function 'cos' for input arguments of type 'char'.

3 次查看(过去 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

采纳的回答

Sabin
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 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by