Getting the max value of a certain column, fetching the entire row from a 3D matrix and write those in a new matrix
2 views (last 30 days)
Show older comments
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 Comments
Sindar
on 20 Jan 2020
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)?
Answers (1)
KSSV
on 20 Jan 2020
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
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!