Borrar filtros
Borrar filtros

how to add a single blank row in a table

171 visualizaciones (últimos 30 días)
Abdul Suleman
Abdul Suleman el 28 de Mzo. de 2020
Comentada: winkmal el 8 de En. de 2024
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 comentarios
Abdul Suleman
Abdul Suleman el 28 de Mzo. de 2020
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 el 28 de Mzo. de 2020
Editada: Adam Danz el 29 de Mzo. de 2020
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')

Iniciar sesión para comentar.

Respuesta aceptada

Adam Danz
Adam Danz el 28 de Mzo. de 2020
Editada: Adam Danz el 31 de Mzo. de 2020
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 comentario
winkmal
winkmal el 8 de En. de 2024
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).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by