Did you read doc on strncmp?
Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
How can I compare cells of 2 matrices to see if part of the string is the same?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have 2 datasets for my subjects and due to blinding of the documents the order of the subjects in the 2 matrices I have does not match. Example:
cell array 1:
WTCdatanames_sham = {'WTC18_2_2_P16_whis_sham_rec' 'WTC18_2_1_P16_whis_sham_rec' 'WTC18_2_3_P16_whis_sham_rec'}
cell array 2:
WTCdatanames_stim = {'WTC18_2_2_P16_whis_stim_rec' 'WTC18_2_3_P16_whis_stim_rec' 'WTC18_2_1_P16_whis_stim_rec'}
Say, for every column in cell array 1, I want to use the first part (WTC18_2_2) to find the corresponding column in cell array 2. How would I be able to do this? Can I in some way write a loop in which it compares the first 10 letters from a cell in cell array 1 to all cells in cell array 2?
답변 (1개)
Birdman
2018년 3월 28일
This should do it:
loc='WTC18_2_2';
strncmp(loc,WTCdatanames_stim,numel(loc))
and this will return logical
1 0 0
which means loc is located in the first element of WTCdatanames_stim, not others.
댓글 수: 2
Birdman
2018년 3월 28일
Maybe this could be helpful:
n=9; %corresponds to WTC_2_2, WTC_2_1 and WTC_2_3 respectively for i=1:size(WTCdatanames_sham,2) idx(i,:)=strncmp(WTCdatanames_sham{i}(1:n),WTCdatanames_stim,n); end
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!