Problem with converting uitable to table (array2table) with strange number of column names
Hello, I have a UITable that on startup has 4 columns.
I want to create some dummy data (3 columns) and play with the different save options (writecell, writematrix and writetable) to see which one handles NaNs the best and can save the column names.
I am hence steering towards writetable.
However, when I clear the table and re-enter my dummy data via:
uit=app.UITable;
uit.Data=[];
r = randi([0,10],10,3)
uit.Data = [r];
I notice that the number of column names is still 4 and not 3, yet the data size in columns is 3!
T=app.UITable;
vn=T.ColumnName
vn = %UITable Column Names
4×1 cell array
{‘Column 1’}
{‘Column 2’}
{‘Column 3’}
{‘Column 4’}
ans = % UITable Data size
10 3
hence the following fails
T = array2table(data, ‘VariableNames’,vn’)
Error using array2table
The VariableNames property must contain one name for each variable in the table.
Any suggestions please?
(and a 2nd question, most of the time my data is doubles, however occasionally its a cell array – when I want e.g. some text. I assume the only chnage I would need is when creating the table I would use cell2table instead of array2table?)Hello, I have a UITable that on startup has 4 columns.
I want to create some dummy data (3 columns) and play with the different save options (writecell, writematrix and writetable) to see which one handles NaNs the best and can save the column names.
I am hence steering towards writetable.
However, when I clear the table and re-enter my dummy data via:
uit=app.UITable;
uit.Data=[];
r = randi([0,10],10,3)
uit.Data = [r];
I notice that the number of column names is still 4 and not 3, yet the data size in columns is 3!
T=app.UITable;
vn=T.ColumnName
vn = %UITable Column Names
4×1 cell array
{‘Column 1’}
{‘Column 2’}
{‘Column 3’}
{‘Column 4’}
ans = % UITable Data size
10 3
hence the following fails
T = array2table(data, ‘VariableNames’,vn’)
Error using array2table
The VariableNames property must contain one name for each variable in the table.
Any suggestions please?
(and a 2nd question, most of the time my data is doubles, however occasionally its a cell array – when I want e.g. some text. I assume the only chnage I would need is when creating the table I would use cell2table instead of array2table?) Hello, I have a UITable that on startup has 4 columns.
I want to create some dummy data (3 columns) and play with the different save options (writecell, writematrix and writetable) to see which one handles NaNs the best and can save the column names.
I am hence steering towards writetable.
However, when I clear the table and re-enter my dummy data via:
uit=app.UITable;
uit.Data=[];
r = randi([0,10],10,3)
uit.Data = [r];
I notice that the number of column names is still 4 and not 3, yet the data size in columns is 3!
T=app.UITable;
vn=T.ColumnName
vn = %UITable Column Names
4×1 cell array
{‘Column 1’}
{‘Column 2’}
{‘Column 3’}
{‘Column 4’}
ans = % UITable Data size
10 3
hence the following fails
T = array2table(data, ‘VariableNames’,vn’)
Error using array2table
The VariableNames property must contain one name for each variable in the table.
Any suggestions please?
(and a 2nd question, most of the time my data is doubles, however occasionally its a cell array – when I want e.g. some text. I assume the only chnage I would need is when creating the table I would use cell2table instead of array2table?) uitable, array2table, writetable MATLAB Answers — New Questions