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
답변 (1개)
Image Analyst
2016년 10월 13일
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
adriano Uaeca Jr
2016년 10월 13일
adriano Uaeca Jr
2016년 10월 13일
Walter Roberson
2016년 10월 13일
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
2016년 10월 13일
편집: Image Analyst
2016년 10월 13일
Image Analyst
2016년 10월 13일
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
2016년 10월 14일
편집: adriano Uaeca Jr
2016년 10월 14일
Image Analyst
2016년 10월 14일
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/
카테고리
도움말 센터 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!