Issues with tables and writetable from data passed from uitable
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello, I have an array in a uitable that I want to save to a csv file as well as the column headings. It seems out of the write options available (writecell,writematrix, writetable) - it is only writetable that allows this
Writetable appears to work, but when I open the CSV file it hasn't and I can't understand why
This is my code:
T=app.UITable;
data=T.Data;
C=array2table(data); % Create table format
T.ColumnName
C.Properties.VariableNames=T.ColumnName;
C.Properties.Description='Scan Profile';
C = addprop(C,{'ScanStart','ScanTime'},{'table','table'});
C.Properties.CustomProperties.ScanStart = app.scannow;
C.Properties.CustomProperties.ScanTime = app.scantime;
C.Properties
% C.Properties.VariableNames
writetable(C,savepath);
ReportMessage(app,' Data Saved Using Writetable');
And in the command window I get this, indicating all is O.K
ans =
6×1 cell array
{'Idx' }
{'YPos(mm)'}
{'Sep1' }
{'Sep2' }
{'<Sep>' }
{'dpixel' }
ans =
TableProperties with properties:
Description: 'Surface Profile'
UserData: []
DimensionNames: {'Row' 'Variables'}
VariableNames: {'Idx' 'YPos(mm)' 'Sep1' 'Sep2' '<Sep>' 'dpixel'}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
Custom Properties (access using t.Properties.CustomProperties.<name>):
ScanStart: "29-Jan-2025 09:41:35"
ScanTime: '174.2796'
But then the file looks like this:

So no headings.
And When i also try to load via readtable - all of the description and custom propeerrties are not present
ans =
TableProperties with properties:
Description: ''
UserData: []
DimensionNames: {'Row' 'Variables'}
VariableNames: {'Var1' 'Var2' 'Var3' 'Var4' 'Var5' 'Var6'}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
CustomProperties: No custom properties are set.
Use addprop and rmprop to modify CustomProperties.
댓글 수: 0
채택된 답변
Cris LaPierre
2025년 1월 29일
When I use your code, it saves a text file with headers.
T = uitable("Data",rand(10,6)*200);
T.ColumnName = {'Idx' 'YPos(mm)' 'Sep1' 'Sep2' '<Sep>' 'dpixel'};
scannow = datetime('now');
scantime = 174.2796;
data=T.Data
C=array2table(data); % Create table format
T.ColumnName
C.Properties.VariableNames=T.ColumnName;
C.Properties.Description='Scan Profile';
C = addprop(C,{'ScanStart','ScanTime'},{'table','table'});
C.Properties.CustomProperties.ScanStart = scannow;
C.Properties.CustomProperties.ScanTime = scantime;
C.Properties
writetable(C);
However, only the text your see in the text file is saved, This means that most of the properties are lost when saving the data.
type('C.txt')
B = readtable('C.txt')
B.Properties
댓글 수: 11
Cris LaPierre
2025년 1월 29일
Since your uitable is already an app object, rather than pass in T, try updating your code to
data = app.UITable.Data
and
C.Properties.VariableNames=app.UItable.ColumnName;
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!