Getting the max value of a certain column, fetching the entire row from a 3D matrix and write those in a new matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Sindar
am 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)?
Antworten (1)
KSSV
am 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
1 Kommentar
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!