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!