Can't get uitable inputs as matrix.
Show older comments
I'd like to have my code run with matrix entered by the users, but can seem to do well with it using uitable (for 2x2,3x3,4x4 and 5x5 matrixes) using this code.
B = [1,0,-1,-1,0;0,1,0,1,0;0,0,1,0,1;-4,2,0,-5,0;4,0,4,0,0];
b = [0;-2;2;0;10];
if det(B) == 0;
error('sistema sem solucao');
end
A= [B,b];
[m,n]=size(A);
for j=1:m-1
for z=j+1:m
if A(j,j)==0
t=A(j,:);
A(j,:)=A(z,:);
A(z,:)=t;
end
end
for i=j+1:m
a = (A(i,j)/A(j,j));
A(i,:)=A(i,:)-a*A(j,:);
end
end
x=zeros(m,1);
for s=m:-1:1
c=0;
for k=2:m
c=c+A(s,k)*x(k);
end
x(s)=(A(s,n)-c)/A(s,s);
end
x
Answers (1)
Image Analyst
on 13 Oct 2016
If uitable1 is the handle/tag to your table, then to extract the data from it, that your users may have typed into it, retrieve the data property:
tableData = handles.uitable1.Data;
7 Comments
adriano Uaeca Jr
on 13 Oct 2016
adriano Uaeca Jr
on 13 Oct 2016
Walter Roberson
on 13 Oct 2016
You extract the data in the place that you need it for calculation.
You can do the same thing with different tags.
tableData1 = handles.uitable1.Data;
tableData2 = handles.uitable2.Data;
try
result = tableData1 \ tableData2;
handles.uitable3.Data = result;
catch
%the data in the tables was the wrong shape... or the left table was not invertable
....
end
adriano Uaeca Jr
on 13 Oct 2016
Edited: Image Analyst
on 13 Oct 2016
Image Analyst
on 13 Oct 2016
Not sure exactly what your algorithm is doing but if you want an element-by-element divide, use dot forward slash instead of backslash
result = tableData1 ./ tableData2;
The tables have to be exactly the same size if you do that.
adriano Uaeca Jr
on 14 Oct 2016
Edited: adriano Uaeca Jr
on 14 Oct 2016
Image Analyst
on 14 Oct 2016
OK, but what are you struggling with? Just use GUIDE, place two tables onto the GUI, plus a button, and in the callback of the button, place the code I gave you to get the current data in the table. Then do something with the data. http://blogs.mathworks.com/videos/category/gui-or-guide/
Categories
Find more on Develop Apps Using App Designer 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!