how to extract subarray of cell array based on logical condition?

조회 수: 7 (최근 30일)
Will Swaston
Will Swaston 2018년 5월 9일
편집: Stephen23 2018년 5월 9일
Hi everyone, I have a cell array of the form (but with lots more data)...
'TS-G5-box11-001_0000_-0.0_May01.mrc' 'box11' '001' '-0.0' 'box11_tomo_001'
'TS-G5-box11-001_0001_2.0_May01.mrc' 'box11' '001' '2.0' 'box11_tomo_008'
I'm struggling with something that should be really easy, I want to be able to access a subarray that just shows everything that contains 'box11_tomo_001' or 'box11_tomo_001', is there an easy way to achieve this?
Cheers,
Will

채택된 답변

KSSV
KSSV 2018년 5월 9일
Read about strfind

추가 답변 (1개)

Stephen23
Stephen23 2018년 5월 9일
편집: Stephen23 2018년 5월 9일
Actually all you need is strcmp. Given:
C = {...
'TS-G5-box11-001_0000_-0.0_May01.mrc' 'box11' '001' '-0.0' 'box11_tomo_001'
'TS-G5-box11-001_0001_2.0_May01.mrc' 'box11' '001' '2.0' 'box11_tomo_008'};
>> idx = strcmp(C(:,5),'box11_tomo_001')
idx =
1
0
If you have multiple string that you want to match then ismember can be useful:

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by