Sort 3D matrix depending on specific column

1 回表示 (過去 30 日間)
Ali Kareem
Ali Kareem 2016 年 5 月 14 日
回答済み: Azzi Abdelmalek 2016 年 5 月 14 日
Hello,
I have 3D matrix (10*10*4) and I am trying to short each slice depending on the 2 column after that and depending on column 2 I want to delete all rows that have a value on column 2 less than 1 and greater than 17.
I used this code to sort but it is not working
clc;
clear;
A = rand(10,10,4)
column = 2;
[values,indices] = sort(A(:,column,:))
B = A(indices,:,:)
Thanks
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 14 日
After deleting some rows, your slices will get different sizes, have you thought about that?
Ali Kareem
Ali Kareem 2016 年 5 月 14 日
編集済み: Ali Kareem 2016 年 5 月 14 日
Hello,
Thank you for your reply. No, it will the same. because this data is a grid and I checked that. but I will get new 3D matrix with new size

サインインしてコメントする。

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 14 日
%-----------Example----------
A=randi(30,10,10,4)
%--------------------------------
out=cell(1,k);
for k=1:size(A,3)
a=A(:,:,k);
b=sortrows(a,2);
c2=b(:,2);
b(c2<1 | c2>27,:)=[];
out{k}=b
end

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by