Logical expression not working with loop and if statement
古いコメントを表示
I need an array with [1, 1, 0, 1, 0, 0, 1, 1, 0, 1]
N=10;
query_class=9;
n_candidate_class = [9, 9, 4, 9, 5, 5, 9, 9, 5, 9];
imgout = zeros(1,N);
for n = 1:N
for c = 1:N
if query_class == n_candidate_class(n)
imgout(c) = 1;
else
imgout(c) = 0;
end
end
end
3 件のコメント
Walter Roberson
2019 年 11 月 11 日
imgout = n_candidate_class == query_class;
is all that is needed if you want to process all of n_candidate_class
Maxence Boels
2019 年 11 月 11 日
Walter Roberson
2019 年 11 月 11 日
You overwrite each imgout(c ) for each different n value, so you are only getting the result as-if you had run with n=N . You want to be comparing corresponding values, not each one to each other.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!