Separating repeated values in an excel column.
Show older comments
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?
Answers (2)
Scott MacKenzie
on 26 May 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 Comment
Aditya Raghav Trivedi
on 26 May 2021
Edited: Aditya Raghav Trivedi
on 26 May 2021
Scott MacKenzie
on 26 May 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
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!