''Unable to perform assignment because the left and right sides have a different number of elements.''

3 次查看(过去 30 天)
tolerance=0.002; %SETTLING TIME CALCULATE
t=fdev(:,1);
f1=abs(fdev(:,2));
f2=abs(fdev(:,3));
tie=abs(ptie(:,2));
ts=zeros(1,3);
ts(1)=t(max(find(f1>=tolerance)));
ts(2)=t(max(find(f2>=tolerance)));
ts(3)=t(max(find(tie>=tolerance)));
Ts=sum(ts);
it is showing "Unable to perform assignment because the left and right sides have a different number of elements."Why is this happening?

回答(1 个)

dpb
dpb 2020-2-26
ts(1)=t(max(find(f1>=tolerance)));
and friends can return an empty RHS if no element satisfies the condition.
  2 个评论
Zumre Yenen Yilmaz
Zumre Yenen Yilmaz 2020-2-26
Error line ''ts(3)=t(max(find(tie>=tolerance)));''
Actually, this code is inside a function. Tie value is calculated from simulink. It only gives an error on the line I wrote above. it is the first time i get such an error. Cab you help me?
dpb
dpb 2020-2-26
Well, doesn't matter which of the three it is, the same symptom is possible.
What do you want the result to be if there are no elements of tie that are >= tolerance?
You could wrap the line in a try...catch block to ignore and go on which would leave the LH side zero for which ever element(s) did fail.
Or, maybe the problem stems from the fact the variable tie isn't what you think it is? Have you used debugger to see what is actually going on?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by