Replace values in a matrix with ones from other matrix based on some criteria

조회 수: 10 (최근 30일)
Olga
Olga 2014년 8월 27일
댓글: Andrei Bobrov 2014년 8월 27일
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!

답변 (4개)

Iain
Iain 2014년 8월 27일
A(isnan(A)) = B(isnan(A));

Andrei Bobrov
Andrei Bobrov 2014년 8월 27일
i0 = isnan(A);
[ii,jj] = find(i0);
A(i0) = B(sub2ind(size(B),ii+1,jj));

Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 27일
ii=isnan(A)
A(ii)=B(ii+1)

Olga
Olga 2014년 8월 27일
Was not successful, unfortunately :(

카테고리

Help CenterFile Exchange에서 Matrix Operations and Transformations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by