matlab Create growing matrix with for loop that grows by 3 per loop -


so have written this:

hsrxdistpr = squeeze(comdatape_m1(2,7,1,:,isubj)); hsrxdistpl = squeeze(comdatape_m1(2,4,1,:,isubj)); tocomxdistp = squeeze(comdatape_m1(2,10,1,:,isubj));  = 1:2;      hsrxp = nan(8,3*i);      hsrxp(:,i*3) = [hsrxdistpr(:,i) hsrxdistpl(:,i) tocomxdistp(:,i)]; end 

in first part selecting data 5-d matrix, nothing special. that's important here creates 8x2 matrix per line (isubj=2). want add first column of each matrix 8x3 matrix, , second column of each matrix same matrix (creating 8x6 matrix). since number of subjects vary, want in loop. way, if isubj increases 3, should go on create 8x9 matrix.

so tried create matrix grow 3 each iteration of i, selects ith column of each of 3 matrices , puts them in there.

however following error:

subscripted assignment dimension mismatch. 

is possible let matrix grow more 1 in loop? or how should done otherwise?

here problem:

hsrxp(:,i*3) = [hsrxdistpr(:,i) hsrxdistpl(:,i) tocomxdistp(:,i)]; 

you're trying assign n x 3 matrix (rhs) n x 1 vector (lhs). easier use horizontal concatenation:

hsrxp = [hsrxp, [hsrxdistpr(:,i) hsrxdistpl(:,i) tocomxdistp(:,i)]]; 

but mean reallocation @ each step, might slow code down if matrix becomes large.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -