How to reduce matrix size conditionally?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Andi
el 17 de Mzo. de 2022
Editada: Davide Masiello
el 17 de Mzo. de 2022
Hi everyone,
My dataset consists of 194 rows and 5 column. in each row either a non-zero value or NaN. I require to pick the non-zero value (only one). There may be more than one non-zero values but all are same, so i need only one. As a resul the size of output matrix will be 194 by 1.
Thansk.
0 comentarios
Respuesta aceptada
Más respuestas (2)
Davide Masiello
el 17 de Mzo. de 2022
Editada: Davide Masiello
el 17 de Mzo. de 2022
You could use the max function. See below
% here I reproduce your type of matrix
A = rand(194,1);
A = [A,A,A,A,A];
A(logical(randi([0,1],size(A)))) = nan
% Here I perform the required task
A = max(A,[],2)
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!