Problem With Combined for Loop.

조회 수: 1 (최근 30일)
Ot
Ot 2014년 2월 27일
댓글: Mischa Kim 2014년 2월 27일
I have a problem with a combined for-loop. For every value of i, I want to compute j(=101) values of B to analyse further. Right now I tried the loop standing below, but I get the error: ??? Subscripted assignment dimension mismatch in the first line below the for assignments. I already tried to compute it without a loop, and then it works, but not in the loop.
for i= 1:length(A)
for j = 1:(2*50+1)
Ang(i,j) = B([A(1,i)-50]:[A(1,i)+50]);
AngAbs(i,j) = abs(Ang(i,j));
ix1(i) = find(AngAbs(i,j)>0.4,1,'first')+(A(1,i)-50);
ix2(i) = find(AngAbs(i,j)>0.4,1,'last')+(A(1,i)-50);
Dir(i) = sum(B([ix1(i)]:[ix2(i)]));
end
end
I hope you can help me.
  댓글 수: 2
Mischa Kim
Mischa Kim 2014년 2월 27일
편집: Mischa Kim 2014년 2월 27일
What are A and B, size, content?
Ot
Ot 2014년 2월 27일
A = Midpoint of Angle index and Value [2x8] matrix. For this loop I only need the Index = first row.
B = Angle between different samples. This is an [1x619] matrix.
So what I basically want to do is to compute for each Midpoint of the Angle a beginning and end of the angle ( which I do with the threshold.) Then I take the Beginning and End of the Angle, and compete the difference in Angle by summating the differences for each sample.

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

채택된 답변

Mischa Kim
Mischa Kim 2014년 2월 27일
Ot, in the command
Ang(i,j) = B([A(1,i)-50]:[A(1,i)+50]);
you are assigning a vector of length 101 to Ang(i,j), which is a scalar .
  댓글 수: 2
Ot
Ot 2014년 2월 27일
Ok. Thanks for explaining this. How should I fix this?
Mischa Kim
Mischa Kim 2014년 2월 27일
Assuming I correctly understand your problem you could do
for i = 1:length(A)
for j = 1:(2*50+1)
AngAbs = abs(B([A(1,i)-50]:[A(1,i)+50]));
ix1(i) = find(AngAbs>0.4,1,'first')+(A(1,i)-50);
ix2(i) = find(AngAbs>0.4,1,'last')+(A(1,i)-50);
Dir(i) = sum(B([ix1(i)]:[ix2(i)]));
end
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by