Filter löschen
Filter löschen

creating additonal rows of NaN in specific positions

4 Ansichten (letzte 30 Tage)
antonet
antonet am 7 Aug. 2012
Kommentiert: William Garrett am 22 Feb. 2020
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

Akzeptierte Antwort

Oleg Komarov
Oleg Komarov am 7 Aug. 2012
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 Kommentare
antonet
antonet am 7 Aug. 2012
thanks Oleg!
William Garrett
William Garrett am 22 Feb. 2020
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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion 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!

Translated by