필터 지우기
필터 지우기

Convert matrix to Uitable

조회 수: 2 (최근 30일)
Light
Light 2013년 6월 8일
A matrix is here
U(35)=9;
U(44)=29;
A=[-1,1,1;0,-1,0;0,0,-1;1,0,0];
blnA = logical( A == -1 );
blnOut = find(any(A == -1,2));
max(blnOut);
negcolumn = find(A(max(blnOut),:) == -1);
onerow = find(A(:,negcolumn) == 1);
And i just wanna convert that matrix to uitable. Because i need a given row name and column name.
f = figure('Position',[10 10 600 600]);
dat = {-1,1,1;0,-1,0;0,0,-1;1,0,0};
cnames = {'18','29','51'};
rnames = {'12','26','35','44'};
t = uitable('Parent',f,'Data',dat,'ColumnName',cnames,...
'RowName',rnames,'Position',[10 10 590 590]);
max(blnOut)
ans =
3
My expected result is 35.
And will use that value 35 like that
U(ans)=?
U(35)
ans =
9
If i solve it, My whole calculation will be perfect. Please give me your hand
  댓글 수: 1
Image Analyst
Image Analyst 2013년 6월 8일
Why give you a hand here rather than the thousand of other posts on this question that you've posted?

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2013년 6월 8일
This will do it:
U(35)=9;
U(44)=29;
A=[-1,1,1;0,-1,0;0,0,-1;1,0,0];
blnA = sum( A == -1, 2 )
lastRow = find(blnA, 1, 'last')
f = figure('Position',[10 10 600 600]);
dat = {-1,1,1;0,-1,0;0,0,-1;1,0,0}
columnHeaders = {'18','29','51'};
rowHeaders = {'12','26','35','44'};
t = uitable('Parent',f,'Data',dat,'ColumnName',columnHeaders,...
'RowName',rowHeaders,'Position',[10 10 590 590]);
theAnswer = str2double(rowHeaders{lastRow})
% Get that number from U:
finalAnswer = U(theAnswer)
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 6월 8일
Though if you are going to do that, why not just use numeric column names and row names?
columnHeaders = {18,29,51};
rowHeaders = {12,26,35,44};
and then
theAnswer = rowHeaders{lastRow};
Image Analyst
Image Analyst 2013년 6월 9일
편집: Image Analyst 2013년 6월 9일
Yes, that's best, and what I suggested in my other answer in one of Light's duplicate questions (that I didn't delete). The whole intent of the code is just an incomprehensible mess to me - I have no idea what Light wants, and consequently can't suggest a good approach.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by