# Error in a for loop

조회 수: 1(최근 30일)
Nikolaos Zafirakis 2019년 7월 14일
답변: SaiDileep Kola 2019년 7월 17일
I’m trying to run a loop through some measurement but I keep getting this error "Unable to perform assignment because the size of the left side is 3-by-1 and the size of the right side is 2-by-1." Does anyone know a way around this?
o = B(1:50,2);
for ind = 1:length(o)
a1(:,ind) = diff(o);
[c1(:,ind),d1(:,ind)] = find(a1(:,ind)>2^15);
[e1(:,ind),f1(:,ind)] = find(a1(:,ind)<-2^15);
o(c1(:,ind)+1:e1(:,ind)) = o(c1(:,ind)+1:e1(:,ind))-2^16; % Error Happens here
end
##### 댓글 수: 4표시숨기기 이전 댓글 수: 3
Nikolaos Zafirakis 2019년 7월 14일
Original data
The result after 2 iterations of the code i showed you (I want to run what I showed you in a loop).

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

### 답변(1개)

SaiDileep Kola 2019년 7월 17일
Hi,
I see that you get the error in 3rd line in the for loop not in the of 4rth line as you mentioned, I think your use case can be realized with the following code.
o = B(1:50,2);
for ind = 1:length(o)
a1 = diff(o);
c1 = find(a1>2^15);
e1 = find(a1<-2^15); %Error happens here
o(c1+1:e1) = o(c1+1:e1)-2^16; % Error doesn't occur here
End

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

### Community Treasure Hunt

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

Start Hunting!

Translated by