필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
brett cursey
brett cursey 2018년 2월 15일
답변: Sabin 2024년 1월 19일
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