How do I make an if statement based on whether an index is part of a vector of numbers?
조회 수: 11 (최근 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!