Compare strings and use data

조회 수: 1 (최근 30일)
Isma_gp
Isma_gp 2016년 7월 8일
댓글: Isma_gp 2016년 7월 8일
Hi,
I have a 1x16cell (channel) and a 1x16cell (data). - Each cell of channel has 1x53cell with the 53 channel names ('AG1', 'AG2', 'TRT', 'BBW'....). - Each cell of data has 100x53cell with the data for each of the 53 channels.
In addition, I have created a 1x3cell with the channel names that I'm looking for, i.e. 'AG5', 'AG7','AG19'
I need to go through the 16 cells of channel, find which columns correspond to the names I'm looking for in each of the 16 cases, and then retrieve data from data cell for those columns in each of the 16 cells.
Can I get some help with this?
thanks

채택된 답변

Guillaume
Guillaume 2016년 7월 8일
To find the column location of your three channels in the list of channels you would use ismember. You then use the second return value to index into your data cell array.
To repeat for the 16 cells, you can either use a standard for loop, or cellfun:
seekedchannels = {'AG5', 'AG7', 'AG19'};
seekeddata = cell(size(data));
for cidx = 1:numel(data)
[~, location] = ismember(seekedchannels, channel{cidx});
seekeddata{cidx} = data{cidx}(location);
end
cellfun would not be so convenient in this case, because you can't grab the 2nd return value of ismember with an anonymous function.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by