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

采纳的回答

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