フィルターのクリア

creating additonal rows of NaN in specific positions

4 ビュー (過去 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 Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by