Compare strings and use data

1 visualización (últimos 30 días)
Isma_gp
Isma_gp el 8 de Jul. de 2016
Comentada: Isma_gp el 8 de Jul. de 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

Respuesta aceptada

Guillaume
Guillaume el 8 de Jul. de 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.

Más respuestas (0)

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by