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?

답변 (2개)

Scott MacKenzie
Scott MacKenzie 2021년 5월 26일

0 개 추천

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

Aditya Raghav Trivedi
Aditya Raghav Trivedi 2021년 5월 26일
편집: Aditya Raghav Trivedi 2021년 5월 26일
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.

댓글을 달려면 로그인하십시오.

Scott MacKenzie
Scott MacKenzie 2021년 5월 26일

0 개 추천

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

카테고리

제품

릴리스

R2020b

태그

질문:

2021년 5월 26일

답변:

2021년 5월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by