Getting the max value of a certain column, fetching the entire row from a 3D matrix and write those in a new matrix
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have a 3D matrix Once_Still_3D of form 68 x 8 x 30, with 30 being the timesteps. I need to find the max value of column 3 from each timestep, fetch the corresponding row and put the row in a new matrix where the row index is same as the timestep index of the 3D matrix.
for k=1:30
[~,idx]=max(Once_Still_3D(:,3,k));
Out(k,:)=Once_Still_3D(idx,:,k);
end
Using this code results in repetition of values found with k=1 in the output file Out.
Here's the output:
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
113.500000000000 68 0.172359450012208 0.0262343597381685 0 0 0 0
Kindly help.
2 件のコメント
Sindar
2020 年 1 月 20 日
To me, this looks like it should work. I'd check your data. Does Once_Still_3D(:,3,1) look different from Once_Still_3D(:,3,2)?
回答 (1 件)
KSSV
2020 年 1 月 20 日
A = rand(68,8,30) ; % randmom data for demo
col = 3 ; % third column from which max to be seeked
[m,n,p] =size(A) ; % dimensions
iwant = zeros(p,n) ; % initialze the required
for i = 1:p
[val,id] = max(A(:,3,i)) ;
iwant(i,:) = A(id,:,i) ;
end
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!