我有一个返回结构的函数,我希望返回有一个有意义的名称,因此我希望它有名称,如
sec.t< 0.25
即t <0.25是我的变量并且为此返回。
任何帮助真的很感激。
function sec = sepfunc(intensdata)
lengthofdata=length(intensdata);
count1=0;
count_2=0;
count_3=0;
count_4=0;
count_5=0;
count_6=0;
count_7=0;
count_8=0;
for i= 1:lengthofdata %loop to seperate count number of data in 5 groups
if (intensdata(i,1)<0.025)
count1=count1+1;
elseif (intensdata(i,1)>=0.025 && intensdata(i,1)<0.05)
count_2=count_2+1;
elseif (0.05<=intensdata(i,1) && intensdata(i,1)<0.1)
count_3=count_3+1;
elseif (0.1<=intensdata(i,1) && intensdata(i,1)<0.125)
count_4=count_4+1;
elseif (0.125<=intensdata(i,1) && intensdata(i,1)<0.15)
count_5=count_5+1;
elseif (0.15<=intensdata(i,1) && intensdata(i,1)<0.175)
count_6=count_6+1;
elseif (0.175<=intensdata(i,1) && intensdata(i,1)<0.2)
count_7=count_7+1;
elseif (intensdata(i,1)>=0.2 )
count_8=count_8+1;
end
end
disp(count1);
disp(count_2);
disp(count_3);
disp(count_4);
disp(count_5);
disp(count_6);
disp(count_7);
disp(count_8);
j=1;
k=1;
l=1;
m=1;
n=1;
o=1;
p=1;
x=1;
low_sec=[count1];
lowmid_sec=[count_2];
middle_sec=[count_3];
upmid_sec=[count_4];
upper_sec=[count_5];
for i= 1:lengthofdata %to seperate original data into 5 different sub-groups.
if (intensdata(i,1)<0.05)
low_sec(j,1)=intensdata(i,1);
j=j+1 ;
elseif(0.05<=intensdata(i,1) && intensdata(i,1)<0.1)
lowmid_sec(k,1)=intensdata(i,1);
k=k+1;
elseif(0.1<=intensdata(i,1) && intensdata(i,1)<0.15)
middle_sec(m,1)=intensdata(i,1);
m=m+1;
elseif(0.15<=intensdata(i,1) && intensdata(i,1)<0.2)
upmid_sec(n,1)=intensdata(i,1);
n=n+1;
elseif( intensdata(i,1)>=0.2)
upper_sec(x,1)=intensdata(i,1);
x=x+1;
end
end
sec.low_sec = low_sec;
sec.lowmid_sec = lowmid_sec;
sec.middle_sec = middle_sec;
sec.upmid_sec = upmid_sec;
sec.upper_sec = upper_sec;
end
所以我想将low_sec改为t&lt; 0.025和0.025之类的东西
答案 0 :(得分:6)
你不能这样做。引自The MathWorks guidelines on variable names:
有效的变量名称以字母开头,后跟字母,数字或下划线。
<
字符是运算符。大多数其他编程语言也不允许这样做。建议使用<
运算符的函数名称:lt
(help lt
)。
答案 1 :(得分:2)
由于你不能在变量名中加入异常字符,我可以看到两种方法:
t_lt_0_025
s.name='t<0.025'