请问在matlab中if不能嵌套到case语句中吗?以下是我的m文件的程序请高手指点错在哪里了?

来源:百度知道 编辑:UC知道 时间:2024/06/03 13:56:08
function [t1,t2,t3,t4] = f(N,U,theta)
% This block supports an embeddable subset of the MATLAB language.
% See the help menu for details.
Ts=1/2e4;%Carrier Cycle.
Udc=100;
t11=U*cos(theta);
t22=U*sin(theta);
switch(N)
case 1
if t11+t22>Ts
{t1=Ts*t11/(t11+t22);t2=Ts*t22/(t11+t22);t3=0;t4=0;}
else
{t1=((Ts*cos(theta))/(2*sqrt(2)*Udc))*(sqrt(2)*Udc/(sin(theta)+cos(theta))+U);
t2=((Ts*sin(theta))/(2*sqrt(2)*Udc))*(sqrt(2)*Udc/(sin(theta)+cos(theta))+U);
t3=((Ts*cos(theta))/(2*sqrt(2)*Udc))*(sqrt(2)*Udc/(sin(theta)+cos(theta))-U);
t4=((Ts*sin(theta))/(2*sqrt(2)*Udc))*(sqrt(2)*Udc/(sin(theta)+cos(theta))-U);}
end
break;
运行是出错如下:
Parse: The expression to the left of the equals sign is not a valid target for an assignment.

Function 'Turn-on Time' (#18.262.263), line 11, column 12:
"="

matlab的if判断是不需要大括弧的
if t11+t22>Ts
{t1=Ts*t11/(t11+t22);t2=Ts*t22/(t11+t22);t3=0;t4=0;}
改成
if t11+t22>Ts
t1=Ts*t11/(t11+t22);t2=Ts*t22/(t11+t22);t3=0;t4=0;
不然马特拉博以为{t1是一个变量 而变量名不合法 所以就error了
else下面也一样