Can't get uitable inputs as matrix.

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

Antworten (1)

Image Analyst
Image Analyst am 13 Okt. 2016

1 Stimme

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 Kommentare

adriano Uaeca Jr
adriano Uaeca Jr am 13 Okt. 2016
where do I type this, under the pushbotton or under the Uitable callback? and can I have the same (tableData = handles.uitable1.Data;) with only different tags for the 2 uitables I have?
adriano Uaeca Jr
adriano Uaeca Jr am 13 Okt. 2016
I'm sorry if it is too much to ask, do you somewhere where I can see this implemented step by step(or a similar situation) cause I've been struggling with this and it is due sunday.
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
adriano Uaeca Jr am 13 Okt. 2016
Bearbeitet: Image Analyst am 13 Okt. 2016
Under the pushbotton I wrote :
function pushbutton1_Callback(hObject, eventdata, handles)
tableData1 = handles.uitableB.data;
tableData2 = handles.uitableb.data;
result = tableData1 \ tableData2;
handles.uitable3.Data = result;
and then continued with the code above.
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
adriano Uaeca Jr am 14 Okt. 2016
Bearbeitet: adriano Uaeca Jr am 14 Okt. 2016
It is solving a nxn matrix using gauss elimination method. So I need to have two, sized like this nxn = nx1 as input and one nx1 as output. The gentleman in the comment above suggest that I use a uitable for thme (both as output and input) but I am struggling with that.
Thank you for your help.
Image Analyst
Image Analyst am 14 Okt. 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/

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 13 Okt. 2016

Kommentiert:

am 14 Okt. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by