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!