Why does my matrix looks empty when it's not?

조회 수: 1 (최근 30일)
Giulia Di Giorgio
Giulia Di Giorgio 2023년 3월 11일
댓글: Giulia Di Giorgio 2023년 3월 12일
Hello, I'm trying to code an UItable where the user is free to add and delete as many rows as they want to. I need the data entered by the user to do some calculus but when I use the get function and then transfer that to a matrix, it runs ok but shows an empty matrix M.
Ps. My add and delete row work just fine, the problem is somewhere else
tabla={'','',''};
app.UITable.Data=tabla;
%I called "tabla" as a global because the code above is in a
%startupFCN button
global tabla
datos = get(tabla, 'Data');
M= cell2mat(datos);

채택된 답변

Walter Roberson
Walter Roberson 2023년 3월 11일
When you global a variable after assigning a local value to the variable in the same workspace, then the local value is removed and the current global value replaces it.
tabla={'','',''};
app.UITable.Data=tabla;
global tabla
is like clear tabla right before the global tabla -- unless, that is, tabla was already global in the workspace.
Furthermore, you get(tabla, 'Data') but is tabla a UITable ? Or is it a cell array of character vectors like you assigned in your code?
Your code appears to be confusing the contents of the UITable and the handle of the UITable.
  댓글 수: 5
Walter Roberson
Walter Roberson 2023년 3월 12일
function calculateButtonPushed(app, event)
datos = app.UITable.Data;
M = cell2mat(datos);
end
Giulia Di Giorgio
Giulia Di Giorgio 2023년 3월 12일
Thank you very much

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by