How to save data of UITABLE in Workspace

조회 수: 5 (최근 30일)
Suraj Srivastava
Suraj Srivastava 2015년 2월 18일
댓글: Giorgos Papakonstantinou 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 CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by