Error message on if functions with two arrays

Hi,
Using two if conditions, I'm trying to compare the subsequent values of an array and the second value of these with the same row of another vector. Somehow, it returns the error message, that the index exceeds the matrix. In excel, it's just a simple if function IF(AND(A1<>A2,A2=B2),1,0). Any idea where I'm running wrong? I kindly attached the matlab code, too:
wi1 = zeros (N,1);
for i=1:N if roi1(i+1)~= roi1(i) && roi1(i)== buobem(i) wi1 = 1; else wi1 = 0; end end
Any help would be very much appreciated, please. Thank you

 採用された回答

Star Strider
Star Strider 2017 年 11 月 17 日

1 投票

Guessing here, because of the paucity of information.
Consider:
for i=1:N-1
instead.

2 件のコメント

Tobias Barton
Tobias Barton 2017 年 11 月 17 日
exactly that, thank you very much indeed!
Star Strider
Star Strider 2017 年 11 月 17 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2017 年 11 月 17 日
編集済み: Andrei Bobrov 2017 年 11 月 17 日

1 投票

wi1 = zeros (N,1);
for ii=2:N
if roi1(ii-1)~= roi1(ii) && roi1(ii)== buobem(ii)
wi1(ii) = 1;
else
wi1(ii) = 0;
end
end
or
roi1 = roi1(:);
buobem = buobem(:);
wi1 = [0; diff(roi1)~=0 & roi1(2:end)== buobem(2:end)];

カテゴリ

質問済み:

2017 年 11 月 17 日

編集済み:

2017 年 11 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by