Extracting Data from Table
Afficher commentaires plus anciens
I am attempting to sort a large set of 3D data, into 2D frames. For context, the data I have imported is a text file and I want to seperate the text file into seperate tables, which all have the same X value. I had previously done this by creating several ID variables...
idx_250 = FFF1.x_coordinate == 0.25;
x_250 = FF1(idx_250,:);
This was repeated for each X value from 0.25 to 4, in 0.25 intervals. In attempt to neaten this up I tried to create a for loop.
for i = 1 :length(xv1)
id = FFF1.x_coordinate == xv1(i);
idTable = FFF1(id,:);
%Here I will process the data within idTable and save it in an appropriate array
end
Here, xv1 is a vector containing all of my x values [0.25 0.5 ... 4].
However, when i = 1 and xv1(i) therefore equals 0.25, the id vector only has one true value. However if I put: id = FFF1.x_coordinate == 0.25, there is no problem. Could someone please explain why it would work if i directly type 0.25 vs a variable with the same value? Thanks!
1 commentaire
Réponse acceptée
Plus de réponses (1)
If FFF1.x_coordinate == xv1(i) gives a different result than FFF1.x_coordinate == 0.25, then xv1(i) is not equal to 0.25. You don't show how xv1 is constructed, so I can't comment on why xv1(1) is not exactly 0.25.
Regardless, here is a way to split a table into a cell array of tables based on the value of one table variable (in this case 'x'):
x = randi(16,100,1)/4; % x: random values amongst {0.25, 0.5, ..., 3.75, 4}
y = randn(100,1); % y: some other random values
z = randn(100,1); % z: some other random values
T = table(x,y,z)
% split T into cell array of tables C, based on value of T.x
vars = T.Properties.VariableNames;
C = splitapply(@(varargin){table(varargin{:},'VariableNames',vars)},T,findgroups(T.x))
% show the tables contained in cell array C
C{:}
1 commentaire
Rhiannon
le 27 Jan 2025
Catégories
En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!