Issues with tables and writetable from data passed from uitable
72 ビュー (過去 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 日 13:36
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 日 20:21
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!