How to rank 3d matrix across 2 dimensions
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi Everyone,
I have 5 variables of gridded data that are identical in size (361x181 matrices). I have run these through different scenerios for my anaylsis and now am trying to compare the changes. What I would like to do is create a 3-d matrix of all the variables sorted by highest to lowest (361x181x5) but retain the "name" of the vairable so I can say this variable had the most change at this location.
From what I have been able to find online the best way seems to be to create a cell of off the variables and then sort.
The issue i am having is sorting the cell along the correct dimesions with the associated names. See the code I've tried so far below, the variables are attached
iVars = zeros(361,181,5);
iVars(:,:,1) = var1;
iVars(:,:,2) = var2;
iVars(:,:,3) = var3;
iVars(:,:,4) = var4;
iVars(:,:,5) = var5;
iNames = {'Var 1','Var 2','Var 3','Var 4','Var 5'};
[~,VarSORT]=sort(iVars,3,'descend');
iNames(VarSORT);
Any help or suggestions is greatly appreciated!
4 comentarios
Respuestas (2)
Matt J
el 7 de Nov. de 2022
Is this (simplified) not what you want?
iVars=rand(3,3,5);
iNames = {'Var 1','Var 2','Var 3','Var 4','Var 5'};
[~,VarSORT]=sort(iVars,3,'descend');
iNames=iNames(VarSORT)
0 comentarios
Bruno Luong
el 7 de Nov. de 2022
iNames(VarSORT);
won't change iNames, you need to assign the expression to a variable VarsRank
iVars = zeros(361,181,5);
iVars(:,:,1) = var1;
iVars(:,:,2) = var2;
iVars(:,:,3) = var3;
iVars(:,:,4) = var4;
iVars(:,:,5) = var5;
iNames = {'Var 1','Var 2','Var 3','Var 4','Var 5'};
[~,VarSORT]=sort(iVars,3,'descend');
VarsRank = iNames(VarSORT); % Assign the result to a variable
0 comentarios
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices 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!