How to efficiently find the index cell-string and cell-number?
이전 댓글 표시
Dear Matlab Coder,
The idea was to find the index if each of the row fulfill the following condition, such as
Second column of ROW contain the string= Acond Third column of ROW contain the string = SS1 Seventh column of ROW contain the number = 1
Manually inspect, the index that fulfill the following condition are index 4 15 26.
To automated the procedure, the following code is realize. The mat file is attached together in this question
load ('raw.mat')
index1 = find((strcmp(raw (:,2), 'ACond') & (strcmp(raw (:,3), 'SS1'))));
index2 = find([raw{:,7}] == 1);
As notice in the above line, I had to used two index. I believe this the last two line can be combined to get a compact representation. So, the following code is proposed
load ('raw.mat')
index1 = find((strcmp(raw (:,2), 'ACond') & (strcmp(raw (:,3), 'SS1')) & ([raw{:,7}] == 1)));
However, the proposed code is not working as intended. May I know the workaround for this problem?.
To add, may I know a more compact representation if the condition are to be extended, say
index1 = find( (strcmp(raw (:,1), 'Sub3') & (strcmp(raw (:,2), 'ACond') & (strcmp(raw (:,3), 'SS1'))...
& ([raw{:,5}] == 4)) & ([raw{:,7}] == 1)));
Thanks in advance for the time entertaining this problem
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!