Pairing row indices with multiple tables
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have one vector of row indeces row= 2 1 2 2 12 21 22 13 19 1 2 4 3 4 1 1, these tell me the rows associated with a max value. I have a vector of 16 tables called databin. I'm trying to associate the row indeces with the tables. For example for the first row: row indece 2 for table 1, row indece 1, from table 2, row indece 2 from table 3. etc... and then put all the data associated from the row indeces and put it in a new table. The problem is, in my for loop, it just gives repeating the row indece for the first table , For example it gives me the row indece 2 for the first table, row indece 1 for the first table, row indece 2 for the first table-- that's not what I want. Can someone help me with this??
1 comentario
Cris LaPierre
el 11 de Ag. de 2021
There may be an easier way, but I would want to start from the orginal 16 tables. Save your tables to a mat file and attach it to your post using the paperclip icon.
Respuestas (2)
Cris LaPierre
el 12 de Ag. de 2021
Note that max has a calling syntax that returns the index of the max it finds.
I would use the following code instead of your for loop.
load databin.mat
Varnum1=11 %chloro
A = cell2mat(reshape(databin,1,1,length(databin)));
[val,ind] = max(squeeze(A(:,Varnum1,:)),[],'omitnan')
As for obtaining a final 2D matrix of just the rows corresponding to the max values of chloro, that can be accomplished with some reshaping magic.
r = ind + [0,cumsum(repmat(size(A,1),1,size(A,3)-1))];
B = cell2mat(databin);
B = B(r,:)
% Just to verify that the values in column 11 are the max values
B(:,Varnum1)
0 comentarios
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!