How to separate four columns on the basis of 5th column
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I hope you are doing well. I have the following Dataset in which I have five column. I want to seperate the data based on fifth column.
Like if the fifth column has the value 1, then all the four column related to value 1 save in new cell.
0 comentarios
Respuestas (2)
Harsh Saxena
el 1 de Jun. de 2023
Hi,
To do this you can use the following logic:
% just to load data
data = load('Dataset.mat');
x = data.Dataset;
%
A = x([x(:, 5)] == 1, :);
A will be an array which will contain only the rows with fifth column element as 1.
Hope this helps!
Stephen23
el 1 de Jun. de 2023
Editada: Stephen23
el 1 de Jun. de 2023
format short G
S = load('Dataset.mat');
D = S.Dataset
Method one: ARRAYFUN:
V = D(:,5);
U = unique(V)
C = arrayfun(@(x)D(x==V,:),U,'uni',0)
Method two: ACCUMARRAY:
V = D(:,5);
W = (1:numel(V));
C = accumarray(V,W(:),[],@(x){D(x,:)})
0 comentarios
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!