필터 지우기
필터 지우기

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 CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by