How to apply uitable to compute and display values those two purposes at the same time?
5 views (last 30 days)
Show older comments
I am a university student who recently study something related to computing and apply Matlab to solve some engineering problem. This time I am trying to using the GUI application which involve the uitable that I have never used before. I tried to made a GUI shown as below, all thing is going well and only one obstacle is the uitable. I had searched the stuff about the cell array and still no clue on using the uitable to display variable values or even the function will retrieve the data from the table to computate values for the next row.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/280630/image.jpeg)
I think there is 2 ways to solve the problem:
1) Keep the current function and hide the variables until the computation is ended then display all the values into uitable. Its seem to be easy to handle on the complexity. or
2) Modified the code and make function will retrieve the data from the table to computate values for the next row and repeat in loops during its operation. Its sound to be messy for me as a mechanical eng. student, not a student from computer engineering or a smart guy on mathematics.
Anyway, I still unable to know how to coding for input my data into the uitable. Can someone give me a hand on provie some clear, practical solutions or some inspiration for me to solving this problem? Thx.
Here is the code of the function currently using in this GUI:
(This is a bisection algorithm that will fprint the values on the command window.)
function run_button_Callback(hObject, ~, handles)
% hObject handle to run_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
func = get(handles.func_input, 'String');
xL = str2double(get(handles.xL_input, 'String'));
xU = str2double(get(handles.xU_input, 'String'));
Es = str2double(get(handles.Es_input, 'String'));
imax = str2double(get(handles.imax_input, 'String'));
%% Formatting Output:
fprintf(' ---------------------------------------------------------------------------------------------\n')
fprintf(' It. xL xR xU f(xL) f(xR) f(xU) |%% Err|\n\n');
%% Initial Conditions:
iter = 0;
xR_P = NaN; % The First Old Estimate Of Root Is Unknown.
%% Computation:
F_xL = feval(func, xL);
F_xU = feval(func, xU);
% Condition 01:
if (F_xL * F_xU > 0)
T01
else
while (1) % If (F_xL * F_xU < 0)
xR = (xL + xU) / 2;
F_xR = feval(func, xR);
% Compute Perc. Relative Appr. Error:
if (xR ~= 0)
Ea = abs((xR - xR_P) / xR) * 100;
end
% Output:
fprintf(' %3.0f %12.6f %12.6f %12.6f %11.6f %11.6f %11.6f %10.6f %%\n', iter, xL, xR, xU, F_xL, F_xR, F_xU, Ea);
fprintf(' >---\n\n')
% Condition 02:
Test = F_xL * F_xR;
if (Test < 0)
xU = xR;
F_xU = F_xR;
elseif (Test > 0)
xL = xR;
F_xL = F_xR;
else
Ea = 0;
end
% Increment Settings:
xR_P = xR; % Update The Old Estimate Of The Root
iter = iter + 1;
% Condition 03:
if (Ea < Es) %(Case: 1)
set(handles.status_output, 'String', 'Tolerance Is Satisfied.');
break
end
% Condition 04:
if (iter > imax) %(Case: 2)
set(handles.status_output, 'String', 'Iteration Limit Exceeded.');
break
end
end
fprintf(' ---------------------------------------------------------------------------------------------\n')
handles.xR_output.String = sprintf('%.6f', xR);
set(handles.iter_output, 'String', iter);
end
% Update handles structure
guidata(hObject, handles);
Note: T01 is a m.file which will popup a GUI window to show the error message if f(xl)*f(xu) > 0, it works properly.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/280631/image.jpeg)
0 Comments
Answers (1)
Peng Li
on 30 Mar 2020
Sorry didn't quite get your problem. are you trying to update the uitable as program is runing?
If it involves a loop in your callback, you could do something like
% show table
if app.ind_out == 1 % refresh, app.ind_out indexing your loop
app.ResTable.Data = [];
end
app.ResTable.Data{app.ind_out, 1} = app.yourDataHandle;
app.ind_out = app.ind_out + 1;
5 Comments
Peng Li
on 30 Mar 2020
yeah that structure I provided should meet your need. and yeas the app.ind_out is the loop index. I'm showing the case that I have made it a class property because it might be used elsewhere. easier to share data.
See Also
Categories
Find more on Dialog Boxes in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!