How to save data of UITABLE in Workspace

4 ビュー (過去 30 日間)
Suraj Srivastava
Suraj Srivastava 2015 年 2 月 18 日
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.

採用された回答

Yoav Livneh
Yoav Livneh 2015 年 2 月 18 日
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');

その他の回答 (1 件)

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2015 年 2 月 18 日
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 件のコメント
Giorgos Papakonstantinou
Giorgos Papakonstantinou 2015 年 2 月 18 日
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)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by