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

3 views (last 30 days)
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?

Answers (1)

dpb
dpb on 26 Feb 2020
ts(1)=t(max(find(f1>=tolerance)));
and friends can return an empty RHS if no element satisfies the condition.
  2 Comments
Zumre Yenen Yilmaz
Zumre Yenen Yilmaz on 26 Feb 2020
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 on 26 Feb 2020
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?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!