Hi, i have a matrix 7938x498 with numerical and NaN values. I want to change value to some NaN elements but i don't know exactly their index in the matrix. I make an example to explain it better.
if i have a vector like this A=(NaN,NaN,NaN,NaN,NaN,1,5,7,9,NaN,NaN,NaN,NaN,5,5,53,3,NaN,NaN). How can i change the NaN values beetween 9 and 5 without change the others? Thanks

댓글 수: 5

Scott MacKenzie
Scott MacKenzie 2021년 4월 27일
What you are asking for seems reasonable. However, can you describe the problem in more general terms. What if there are many sequences of numbers interspersed with NaN sequences?
dpb
dpb 2021년 4월 27일
Or, another way to ask the same question -- how do you determine which locations it is that are wanted to be changed? Is it based on the value of the element itself of, in the example given, because it is the sequence after the sequence of finite values and it doesn't matter that 9 is 9 or 5 is 5; just that they are finite?
Giacomo Abrardo
Giacomo Abrardo 2021년 4월 27일
Yes, i have 498 stations and each column of the matrix i made shows the precipitation data of a station. From the first day of activity to the last they have several days of maintenance and they could have event more sequences of NaN elements for a single station. The problem is that i have to apply a recursive formula at any column and i want to change the NaN value with a numerical value of the nearest station.
Giacomo Abrardo
Giacomo Abrardo 2021년 4월 27일
dqb i only need that they are finite. Doesn't matter the exact value
Giacomo Abrardo
Giacomo Abrardo 2021년 4월 27일
that's part of the matrix. I need to change the value 3985 and 3989 from second column

댓글을 달려면 로그인하십시오.

 채택된 답변

the cyclist
the cyclist 2021년 4월 27일

0 개 추천

Here is one way:
% The original data
A = [NaN,NaN,NaN,NaN,NaN,1,5,7,9,NaN,NaN,NaN,NaN,5,5,53,3,NaN,NaN];
% The indices of the numeric values
numericIndices = find(~isnan(A));
% The indices of the NaNs in the gap between the numeric values
gapIndices = setxor(min(numericIndices):max(numericIndices),numericIndices);
% Fill in the values you want to assign
A(gapIndices) = ...

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 NaNs에 대해 자세히 알아보기

태그

질문:

2021년 4월 27일

댓글:

2021년 4월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by