matlab - changing certain elements in a 2D array -


i'm working on algorithm in matlab requires elements of matrix updated regularly , looking how best this. here description of i'm trying achieve:

  1. i have mxn array a , 1xn vector b.
  2. basically, vector b logical index describes column of a need select i.e. c = a(:,b).
  3. unfortunately, logical vector b varies depending on processes. means number of columns in c not fixed.
  4. some other processing use c inputs , produce array d has same size c i.e. size(d) == size(c)
  5. now, need "reshape" d has same size a. tricky part columns in a weren't chosen in #2 above needs replaced nans. of course can crude way of using loops. i'm looking matlab-way i.e. linear or logical indexing, vectorization, etc got stuck @ moment.

some examples make things clearer:

lets

a = [1 2 3; 4 5 6; 7 8 9]  b = [1 0 1]  c = a(:,b) = [1 3; 4 6; 7 9]  

after processing, i'll d = [2 5; 6 7; 3 3]. now, need "reshape" d same size a padding nan i.e. d = [2 nan 5; 6 nan 7; 3 nan 3].

what i've tried far,

atmp = nan(size(a)); btmp = find(repmat(b,[size(b,1),1])); atmp(btmp) = d(btmp); %-> error because d smaller a. 

how about

fulld = nan(size(a)); fulld(:, b) = d; 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -