Separating repeated values in an excel column.

I have two excel columns - one contains 'Names' and other contains 'Reading' ( numerical value between -2 and +2) corresponding to the same.
For each unique name, there are 10-12 readings available.
I need to write a program which reads every unique name from the column and plots all the readings corresponding to that name in a violin plot (I have the code for it).
eg. I must choose one unique entry at a time (say Alpha) and plot all the corresponding readings for alpha on a violin plot. This will give me two plots, one for alpha and another for beta.
How do I read all the repeating values of only one unique entry at a time and perform operations on them?

Respuestas (2)

Scott MacKenzie
Scott MacKenzie el 26 de Mayo de 2021
When you say "plot all the 12 readings", I assume there are exactly 12 readings per name. In this case...
T = readtable('yourdata.xlsx');
names = unique(T{:,1});
j = 1;
for i=1:length(names)
nameLogical = strcmp(T{:,1}, names{i});
M(:,j) = T{nameLogical, 2};
j = j + 1;
end
% plot data in M
Alternatively...
T = readtable('yourdata.xlsx');
T = sortrows(T, 1); % if data are not sorted
M = T{:, 2};
M = reshape(M, 12, [])
% plot data in M

1 comentario

Aditya Raghav Trivedi
Aditya Raghav Trivedi el 26 de Mayo de 2021
Editada: Aditya Raghav Trivedi el 26 de Mayo de 2021
Hey, thanks for your solution. However there has been a miscommunication from my end which I have edited in the question - each name doesnt have exactly 12 readings, it varies between 8-12. Hence this solution solves my problem only partly.

Iniciar sesión para comentar.

Scott MacKenzie
Scott MacKenzie el 26 de Mayo de 2021
If the number of readings varies, as you say, from 8 to 12, then...
T = readtable('yourdata.xlsx');
names = unique(T{:,1});
j = 1;
for i=1:length(names)
nameLogical = strcmp(T{:,1}, names{i});
M(:,j) = T{nameLogical, 2};
M(end+1:12,j) = nan;
j = j + 1;
end
% plot data in M

Productos

Versión

R2020b

Etiquetas

Preguntada:

el 26 de Mayo de 2021

Respondida:

el 26 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by