Is it possible to extract and store data to uitable in GUI

Is it possible to extract a set of data from an equation and store it in a uitable?
I want to extract the output data from an equation to a uitable and then later on export it to excel. Not sure if the first part is possible.
My code that I'm trying to extract data:
C_0 = str2double(get(handles.Input_C_0,'String'));
v = str2double(get(handles.Input_v,'String'));
t = str2double(get(handles.Input_t,'String'));
D = str2double(get(handles.Input_D,'String'));
R = str2double(get(handles.Input_R,'String'));
t_half = str2double(get(handles.Input_t_half,'String'));
X1 = str2double(get(handles.Input_X1,'String'));
X2 = str2double(get(handles.Input_X2,'String')); %%%all user inputs
x = X1:0.1:X2;
lambda = (0.69314718)./t_half;
beta = sqrt((v./(2.*D)).^2+(lambda.*R)./D);
subA = (x-t.*sqrt((v./R).^2+(4.*lambda.*D)./R))./2.*sqrt((D.*t)./R);
subB = (x+t.*sqrt((v./R).^2+(4.*lambda.*D)./R))./2.*sqrt((D.*t)./R);
C1 = (1./2).*exp((v.*x)./(2.*D)).*(exp(-beta.*x).*erfc(subA)+exp(beta.*x).*erfc(subB)); %%%equation with sub equations
C = C1./C_0;
plot(x,(C));
C will generate a graph with values for each x, I wonder if I can put it in a uitable

2 Comments

Which equation. Please post an example in formatted code.

Sign in to comment.

 Accepted Answer

xlswrite('YourFile.xls', [x(:),C(:)])

5 Comments

That's to export it to a Excel file right?
I'm thinking of extracting the data first to a uitable within my MATLAB GUI program before doing that.
data = num2cell([x(:),C(:)]);
set(UiTableHandle, 'Data', data);
stored_data = get(UiTableHandle, 'Data');
xlswrite('YourFile.xls', stored_data);
Note: This form of xlswrite, passing in a cell, requires that you be using MS Windows and have Excel installed on your system. If you are on any other OS or do not have Excel installed, then you would need to use
xlswrite('YourFile.xls', cell2mat(stored_data));
Hey thanx for the reply!
I tried adding it to my code for another button, but somehow it isn't working...
---------------------------
guidata(hObject, handles);
handles.output = hObject;
C_0 = str2double(get(handles.Input_C_0,'String'));
v = str2double(get(handles.Input_v,'String'));
t = str2double(get(handles.Input_t,'String'));
D = str2double(get(handles.Input_D,'String'));
R = str2double(get(handles.Input_R,'String'));
t_half = str2double(get(handles.Input_t_half,'String'));
X1 = str2double(get(handles.Input_X1,'String'));
X2 = str2double(get(handles.Input_X2,'String'));
x = X1:0.1:X2;
lambda = (0.69314718)./t_half;
beta = sqrt((v./(2.*D)).^2+(lambda.*R)./D);
subA = (x-t.*sqrt((v./R).^2+(4.*lambda.*D)./R))./2.*sqrt((D.*t)./R);
subB = (x+t.*sqrt((v./R).^2+(4.*lambda.*D)./R))./2.*sqrt((D.*t)./R);
C1 = (1./2).*exp((v.*x)./(2.*D)).*(exp(-beta.*x).*erfc(subA)+exp(beta.*x).*erfc(subB)); %%% equation with sub equations
C = C1./C_0;
data = num2cell([x(:),C(:)]);
set(DATA_TABLE, 'Data', data); %%% uitable is tagged DATA_TABLE
--------------------------------
If the uitable is tagged DATA_TABLE, then
UiTableHandle = findobj(0,'Tag','DATA_TABLE');
set(UiTableHandle,,'Data', data);
Sweet, it works and the Excel is in the Matlab directory, thanx for the help.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!