How do I make an if statement based on whether an index is part of a vector of numbers?
20 ビュー (過去 30 日間)
古いコメントを表示
Hi, I am using MATLAB R2020a on a MacOS. I am trying to write an 'if' statement such that a command is executed if the index of the for loop if not a part of a vector of values. I have a vector 'abnormal_attractors' which has the index positions of indices that I do not want the command to be executed. I only what the command to be executed for all the index positions apart from these values.
I would very much appreciate any suggestions. Thanks in advance
for currentcycle = 2:length(number_cycles)
abnormal_attractors = [95, 94, 93, 92, 91, 90, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 67, 66, 65, 64, 25, 24, 23, ...
5, 4, 2];
% if currentcycle is not a member of abnormal_attractors vector, then
% execute following 2 lines
previous_expmean_v = current_expmean_v;
previous_expmean_w = current_expmean_w;
end
0 件のコメント
採用された回答
James Tursa
2020 年 12 月 2 日
編集済み: James Tursa
2020 年 12 月 2 日
You can use the ismember( ) function for this. E.g.,
if ~ismember(currentcycle,abnormal_attractors)
previous_expmean_v = current_expmean_v;
previous_expmean_w = current_expmean_w;
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!