フィルターのクリア

how to add a single blank row in a table

171 ビュー (過去 30 日間)
Abdul Suleman
Abdul Suleman 2020 年 3 月 28 日
コメント済み: winkmal 2024 年 1 月 8 日
Dear collegues,
Supose my table is as follows
1 2 3
4 5 6
7 8 9
I want to convert it in:
1 2 3
4 5 6
7 8 9
That is, adding a blank row between some table rows. Can some one help me in this issue?
Thank you for you time.
Best,
Abdul
  2 件のコメント
Abdul Suleman
Abdul Suleman 2020 年 3 月 28 日
Thanks Adam for you help. In fact your answer helps solve my problem only partially. I would like to have " " (white space) instead of NaN. Since I am saving my table as an excel file, it would be easy to replace NaN by " " in Excel environment. Best. Abdul
Adam Danz
Adam Danz 2020 年 3 月 28 日
編集済み: Adam Danz 2020 年 3 月 29 日
Bad news: In Matlab, numeric arrays cannot have empty values as you describe them. Numeric empty values are represented as NaN.
Good news: However, if you use writematrix, the NaN values will be written as empty values in Excel which completes you query :)
M = magic(4);
M([2 5 10]) = nan; %insert NaNs
writematrix(M,'myExcelFile.xlsx')

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2020 年 3 月 28 日
編集済み: Adam Danz 2020 年 3 月 31 日
Note that "missing" values are represented by NaN values for numeric data.
% Create demo table
T = array2table(reshape(1:9,3,3));
% Which row should contain the empty values?
rowNum = 3;
% Create new table with row of empty values
Tnew = T([1:rowNum,rowNum:end], :);
Tnew{rowNum,:} = missing;
Result:
% Original table
T =
3×3 table
Var1 Var2 Var3
____ ____ ____
1 4 7
2 5 8
3 6 9
% Updated table
Tnew =
4×3 table
Var1 Var2 Var3
____ ____ ____
1 4 7
2 5 8
NaN NaN NaN
3 6 9
  1 件のコメント
winkmal
winkmal 2024 年 1 月 8 日
Your solution works like a charm, even for a timetable. Though this can produce a duplicate timestamp (which it does in my case, but this can be fixed afterwards).

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by