Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
brett cursey
brett cursey am 15 Feb. 2018
Beantwortet: Sabin am 19 Jan. 2024
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

Akzeptierte Antwort

Sabin
Sabin am 19 Jan. 2024
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});

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by