How to rank 3d matrix across 2 dimensions
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Matt J
2022-11-7
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 个评论
Bruno Luong
2022-11-7
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!