How to save data of UITABLE in Workspace

3 views (last 30 days)
Hi,
I have a uitable with 3-columns of which first two are fixed, while the 3rd columns receives input from the user. Now I want to save this new data to somewhere like - workspace/excel file/ mat file. I have following code ==
load data.mat columns={'x','y','z'}; ht = uitable(uitable(data,columns,'Position',[25 90 200 200])); newdata =get(h,'Data'); FileName = uiputfile('*.xls','Save as'); xlswrite(FileName,newdata),
Whenever I run this above matlab gives following error, I can't find solution for this. So any suggestion will be heartly appreciated.
In uitable at 46 In new at 7 Error using horzcat The following error occurred converting from char to opaque: Error using horzcat Undefined function 'opaque' for input arguments of type 'char'.
Error in uitable_deprecated (line 40)
Error in uitable (line 47) [thandle, chandle] = uitable_deprecated(varargin{:});
Error in new (line 7) ht = uitable(uitable(data,columns,'Position',[25 90 200 200]));
Kindly help me out. Thank you.

Accepted Answer

Yoav Livneh
Yoav Livneh on 18 Feb 2015
I think you are using uitable wrong. Look at the documentation for this function but I believe it should be something like this:
ht = uitable('Data',data','ColumnName',columns,'Position',[25 90 200 200]);
and then
newdata = get(ht,'Data');

More Answers (1)

Giorgos Papakonstantinou
Giorgos Papakonstantinou on 18 Feb 2015
If you want to get the data whenever the data change use this:
f = figure;
d = randi(100, 7, 3);
t = uitable(f,'Data',d,'ColumnWidth',{50},...
'ColumnEditable', [true true true]);
% GET DATA whenever the data change
set(t, 'CellEditCallback', 'get(t,''Data'')')
  1 Comment
Giorgos Papakonstantinou
Giorgos Papakonstantinou on 18 Feb 2015
I you want specifically to create a variable in workspace whenever data change in you table, try this:
set(t, 'CellEditCallback', 'assignin(''base'',''data2workspace'',get(t, ''Data''))')
or more neatly create a function
function dataChanged(src, evt)
assignin('base','data2workspace',get(src, 'Data'))
end
then
set(t, 'CellEditCallback', @dataChanged)

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!