필터 지우기
필터 지우기

angle and abs function gives me 'Subscript indices must either be real positive integers or logicals.' error

조회 수: 5 (최근 30일)
if strcmp(app.Type_of_analysis.Value,'Exact') && app.Primary.Value == 1
R2_= app.R2.Value*(app.Turns_ratio.Value)^2;
X2_double=str2double (app.X2.Value);
X1_double=str2double(app.X1.Value);
Xm_double=str2double(app.Xm.Value);
X2_=X2_double*(app.Turns_ratio.Value)^2;
V2_=app.Load_voltage.Value*(app.Turns_ratio.Value)^2;
angle= -acosd(app.Power_factor.Value);
Power1= app.Input_Power.Value*app.Percentage_of_loading.Value*0.01;
I_load_magnitude=Power1/V2_;
I_load_= I_load_magnitude*cos(angle*pi/180)+I_load_magnitude*sin(angle*pi/180)*1i;
V_x= V2_+I_load_*(R2_+X2_double);
I_m= V_x/Xm_double;
I_c= V_x/app.Rc.Value;
I_phi= I_m+I_c;
I_input= I_phi+I_load_;
I_input_angle= angle(I_input); ****Error*****
I_input_magnitude= abs(I_input); ****Error*****
Input_voltage= V_x+I_input*(app.R1+X1_double);
app.Input_voltage_magnitude= abs(Input_voltage);
app.Input_voltage_angle= angle(Input_voltage);
Power_factor1= cos(angle(Input_voltage)-I_input_angle);
app.Input_Power.Value=app.Input_voltage_magnitude*I_input_magnitude*Power_factor1;
app.Voltage_regulation.Value=(app.Input_voltage_magnitude-V2_)/V2_*100;
end

채택된 답변

Star Strider
Star Strider 2022년 4월 19일
First the code defines:
angle= -acosd(app.Power_factor.Value);
then later it calls the angle function:
I_input_angle= angle(I_input); ****Error*****
and MATLAB now firmly believes that angle is a variable and not a function because that is what you told it earlier.
The solution is to re-name the ‘angle’ variable to something that does not overshadow the angle function and means something in context, for example ‘pf_angle’.
I do not see that anything is assigned to a variable ‘abs’, however I suspect something similar was done somewhere else in the code. The solution is similar.
.

추가 답변 (1개)

Voss
Voss 2022년 4월 18일
Do you have a variable called abs? To find out, do:
whos abs
If there is one, clear it by doing:
clear abs
This will clear the variable abs from your workspace, allowing you to run the function abs.
  댓글 수: 2
youssef Mostafa
youssef Mostafa 2022년 4월 19일
The error appears in the angle and abs function. and I tried ur solution but I didn't find a variable named abs
John D'Errico
John D'Errico 2022년 4월 19일
You don't understand. This error essentially indicates you have done exactly that. For example, we see this line of code:
angle= -acosd(app.Power_factor.Value);
So you did create a variable named angle. Then you try to use the function angle.
I_input_angle= angle(I_input); ****Error*****
However, this fragment of code is only part of what you have written. Somewhere in that code, you have defined a variable named abs.
DON'T DO THAT!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by