- Find unique values in the x-axis
- For each of the unique value extract corresponding set of values in y-axis.
- As there could be varied number of y-axis values for a unique value in x-axis, I'm converting the results into a cell array. Looking at the screenshot, For x-axis value of "1.10E-05" we have 19 values and for 1.11E-05 we have 8 values. So converting the results to cell array would allow us to have variable number of columns.
Convering a table with multiple y values for a single x value
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I have a csv file. There is more than 36000 datapoints for both x and y . where multiple x cells have same value for different y values. I want to converge it like for different x values of x columns, y column becomes a vector. can anyone give me a code
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/395198/image.jpeg)
0 Commenti
Risposte (1)
Sourabh Kondapaka
il 6 Nov 2020
Modificato: Sourabh Kondapaka
il 6 Nov 2020
This is my approach:
% I'm using an 100x2 matrix as I do not have your dataset.
% I would suggest setting up breakpoints and looking at how the matrices
% 'a', 'b' and 'results' are being changed.
a = zeros(100,2);
a(:,2) = randn(100,1);
% After executing the below for-loop, the first column will have
% values ranging from 0 to 9.
for i = 1:100
a(i,1) = mod(i,10);
end
b = array2table(a);
% I'm changing this so as to reflect a similar pattern as in your dataset
% as discussed in 3rd point of my approach:
b{10,1} = 19;
%Extracting unique values.
unique_values = unique(b{:,1});
% Converting to cell array so as to allow variable number of columns.
results = cell(length(unique_values), 2);
for i=1:length(unique_values)
results{i, 1} = unique_values(i);
results{i, 2} = table2array(b(b.a1 == unique_values(i), 2))';
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Tables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!