creating additonal rows of NaN in specific positions

조회 수: 5 (최근 30일)
antonet
antonet 2012년 8월 7일
댓글: William Garrett 2020년 2월 22일
Dear all,
I have a large matrix (double array of dimension 80000 by 21) and I want to create NaN rows in specific positions.
I have set up a rule [find(gg>300)] according to which I know the positions at which I want to create an additional row that will contain NaNs
For instance, let’s start with a simple example
A=[
2.4332 4.1477;
2.6073 4.5900;
2.2310 3.7442;
2.4555 4.1178;
2.5096 4.1946;
2.7517 4.7802;
2.8372 4.9423;
2.9577 5.1563;
3.2365 5.6061;
3.0658 5.3787;
2.9244 5.0497;
2.6104 4.4623;
2.5419 4.4164;
2.4947 4.3577;
2.5633 4.7050
]
Suppose that the criterion “find” tells me that I have to create additional rows of NaNS in positions 2,4,5,10 Then I want to have
A=[
2.4332 4.1477;
2.6073 4.5900;
NaN NaN
2.2310 3.7442;
2.4555 4.1178;
NaN NaN
2.5096 4.1946;
NaN NaN
2.7517 4.7802;
2.8372 4.9423;
2.9577 5.1563;
3.2365 5.6061;
3.0658 5.3787;
NaN NaN
2.9244 5.0497;
2.6104 4.4623;
2.5419 4.4164;
2.4947 4.3577;
2.5633 4.7050
]
thanks

채택된 답변

Oleg Komarov
Oleg Komarov 2012년 8월 7일
Very similar to your previous question. You have to build the idx accordingly. Nte that the idx stores the row position where you will allocate A in Anew.
pos = [2,4,5,10];
[r,c] = size(A);
add = numel(pos); % How much longer Anew is
Anew = NaN(r + add,c); % Preallocate
idx = setdiff(1:r+add,pos); % all positions of Anew except pos
Anew(idx,:) = A;
  댓글 수: 2
antonet
antonet 2012년 8월 7일
thanks Oleg!
William Garrett
William Garrett 2020년 2월 22일
Hi, I have tried this approach but after the final step I recieve the following error:
'The following error occurred converting from datetime to double: Undefined function 'double' for input arguments of type 'datetime'. To convert from datetimes to numeric, first subtract off a datetime origin, then convert to numeric using the SECONDS, MINUTES, HOURS, DAYS, or YEARS functions'
Are you able to explain to me what I need to do?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by