Getting the max value of a certain column, fetching the entire row from a 3D matrix and write those in a new matrix

조회 수: 1 (최근 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
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)?
Arup Bhattacharya
Arup Bhattacharya 2020년 1월 20일
Yes, matrices for all the timesteps are different. I am also trying to figure this out whether there is a problem with the 3D matrix or whether the max values everywhere is same.

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by