Classify responses into categories
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alejandro Estudillo
el 6 de Mzo. de 2018
Comentada: Guillaume
el 8 de Mzo. de 2018
Hello, hope someone can help me because I am totally blank!
I have a 10 by 6 matrix. Each row reflects the response of one participant and each column represents a different stimulus
responses = rand(10,6)
I also have 6 by 2 cell array. Each rows here represents each of the six stimulus and the column the condition they belong to
stimuli = {'a', 'HF'; 'c', 'MF'; 'g', 'MF'; 's', 'LF'; 'T', 'HF'; 'v', 'LF'}
I would like to classify the data into responses to HF, MF and LF conditions. I know that I would need to use a for loop and probably either if or switch statement, but however I am blank and don't even know how to start.
Thanks!
6 comentarios
Guillaume
el 6 de Mzo. de 2018
So, the first column of stimuli is irrelevant for your question, then? And really all you want to do is split responses into three matrices with columns [1 5] together, columns [2 3] together and columns [2 6] together (according to this particular stimuli cell array)
This can be easily done but the more important question is why? Splitting one variable into multiple variable usually makes subsequent calculations harder rather than easier. Keeping the labels of the columns separated as you have now is probably best.
Respuesta aceptada
Guillaume
el 7 de Mzo. de 2018
As I said in my comments, it is very likely that splitting your matrix is going to make further processing more complicated, not easier. With that caveat:
[catnames, ~, subs] = unique(stimuli(:, 2)); %get unique names and corresponding rows/columns
splitresponses = accumarray(subs, (1:numel(subs))', [], @(cols) {responses(:, cols)});
splitresponses will be a cell array, where splitresponses{i} corresponds to all the responses for catnames{i}. Whatever you do, do not create individual variables for these.
If need be, you can convert the cell array into a structure whose fields are named after the stimuli:
responsesbystimuli = cell2struct(splitresponses, catnames)
but that again is likely to make your processing more complicated.
2 comentarios
Guillaume
el 8 de Mzo. de 2018
To make it easier to understand, this is what the accumarray portion is more or less equivalent to:
splitresponses = cell(max(subs), 1);
for iter = 1:max(subs)
cols = find(iter == subs);
splitresponses{iter} = responses(:, cols);
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Waveform Generation 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!