Compare strings and use data
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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.
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 Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!