Replace values in a matrix with ones from other matrix based on some criteria
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I would appreciate any help to solve this problem. Lets say i have one matrix - A in such form Nan,0,0; Nan,0,0; 37,0,0; 0,0,0;
and another matrix - B, of the same size with some values. What i try to do is to replace Nan with values from B according to the value after Nan. It means that if i have 37, previous Nans should be replaced with correponding values of B from 37 column. So, basically in each column i have a number of Nan rows followed by some number that indicates from which column of B Nan should be replaced to corresponding values. Could you please help me. Thanks beforehand!
1 Kommentar
Andrei Bobrov
am 27 Aug. 2014
Let
A = [nan,0,0; nan,0,0; 37,0,0; 0,0,0];
B = reshape(1:numel(A),size(A));
Anew = ...
Give us the Anew
Antworten (4)
Andrei Bobrov
am 27 Aug. 2014
i0 = isnan(A);
[ii,jj] = find(i0);
A(i0) = B(sub2ind(size(B),ii+1,jj));
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Operations and Transformations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!