Get columns from a matrix
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
gsourop
il 4 Nov 2016
Risposto: Alexandra Harkai
il 4 Nov 2016
Hi everyone! I have a matrix 432x90 and I want to create several subtables from this Table. The pattern I want these new tables to follow goes like this: I would like the first matrix to contain the values of the columns 1,16,31,46,61,76 of the initial matrix, i.e. 1, (1+15=16), (16+15=31), (31+15=46) and so on...the second matrix to get the values of the columns 2,17,32,47,62,77, the exact same case for the 3rd to 15th new matrix. Can I do this in to a loop instead of manually? I would appreciate some help! Thanks a lot in advance.
0 Commenti
Risposta accettata
Alexandra Harkai
il 4 Nov 2016
m; % this is your 432x90 matrix
N = 15; % number of small matrices
res(N).small_matrix = []; % init empty nonscalar struct array for results
cols = 1:size(m, 2);
for n = 1:N
res(n).small_matrix = m(:, mod(cols, N) == mod(n, N));
end
This may not be the best solution though, it is not clear why you need to 'cut up' the initial matrix to smaller ones. If it is about just accessing certain parts of the data, it may not be such a good idea to do the whole thing, but you could access the part you need at any given time using this piece:
m(:, mod(cols, N) == mod(n, N))
0 Commenti
Più risposte (1)
Adam
il 4 Nov 2016
mySubMatrix = myMatrix( :, 1:15:end );
etc.
This smells of ending up with lots of ugly named variables, but they could be put into a cell array instead or similar. You could even just create a function handle to the original table in each case probably.
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrices and Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!