Compare strings and use data

1 Ansicht (letzte 30 Tage)
Isma_gp
Isma_gp am 8 Jul. 2016
Kommentiert: Isma_gp am 8 Jul. 2016
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

Akzeptierte Antwort

Guillaume
Guillaume am 8 Jul. 2016
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.

Weitere Antworten (0)

Kategorien

Mehr zu Numeric Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by