Reputation: 67
I want to retrieve the data from each iteration into each row of the table, I have used, as shown below:
set(handles.tableIteration,'data',vars)
But it has only retrieved the last values from the last iteration into the first row of the table? Why? How can I retrieve all the values in each iteration into the table?
% --- Executes on button press in btnSolve.
function btnSolve_Callback(hObject, eventdata, handles)
% hObject handle to btnSolve (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
syms x
func = handles.editEquation.String;
S = vectorize(char(func)); % For Signs Like %,^,&,.
f = str2func(['@(x) ', func]);
a = str2double(handles.editBeginning.String);
b = str2double(handles.editEnd.String);
n = str2double(handles.editMaximumIteration.String);
error = str2double(handles.editError.String);
%Bisection Method
if f(a)*f(b) > 0
disp('f(a)*f(b) must be less than zero');
else
fx = 2*error;
num = 0;
while(num < n && abs(fx) > error)
fa = f(a);
x = (a+b)/2;
fx = f(x);
if (sign(fx) == sign(fa))
%Retrieving the data to the table
vars = {num2str(a),num2str(b),num2str(x), num2str(fx)};
set(handles.tableIteration,'data',vars)
a = x;
else
%Retrieving the data to the table
vars = {num2str(a),num2str(b),num2str(x), num2str(fx)};
set(handles.tableIteration,'data',vars)
b = x;
end
num = num + 1;
end
end
handles.btnPlot.Enable = 'on';
Upvotes: 1
Views: 54
Reputation: 3071
Using set
method for data
of uitable, sets all the data of the table, to be the value that you send.
Solution 1:
Define all the data you need in the table before setting:
vars = {num2str(a),num2str(b),num2str(x), num2str(fx)};
data = [get(handles.tableIteration, 'Data'); vars];
set(handles.tableIteration,'Data', data)
Solution 2:
Define the exact line you want to set:
vars = {num2str(a),num2str(b),num2str(x), num2str(fx)};
handles.tableIteration.Data(end+1, :) = vars;
Upvotes: 1