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!