필터 지우기
필터 지우기

Why can't I enter any number that is not a one digit number on my UITable?

조회 수: 1 (최근 30일)
Hello, I'm trying to get a column vector from a matrix I withdraw from an UITable. It works perfectly with one digit numbers (ex. 1 2 3 4 ...9) but when I enter 2 or more digit numbers it shows this error: Dimensions of arrays being concatenated are not consistent. For example, this data:
%Obtener los datos de la tabla
tabla=app.UITable.Data;
M=cell2mat(tabla)
%Obtener las columnas de la tabla
h=M(:,1)
tP=M(:,2)
tT=M(:,3)
%Convertir cada columna a vector columna
vh=str2num(reshape(h,[],1))
vtP=str2num(reshape(tP,[],1))
vtT=str2num(reshape(tT,[],1))
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 3월 12일
Note that
h=M(:,1)
and similar lines can only return a (possibly empty) column vector.
vh=str2num(reshape(h,[],1))
and the reshape(h,[],1) can only reshape something into a (possibly empty) column vector before calling str2num. But it is already certain to be a column vector, so the reshape() is unnecessary code.

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

채택된 답변

Walter Roberson
Walter Roberson 2023년 3월 12일
If your uitable contained numeric entries, then the 1 and the 15 in h would be right aligned, like
1
15
but they are left aligned in your image, like
1
15
Therefore your entries are text not numeric. And of course for text, the number of characters in each matters.
You do not show it here, but in your previous questions you have been shown initializing row entries to {'','',''} which are text entries not numeric.
And no, you cannot have blank numeric entries. If you want to switch to numeric entries you should initialize the row to 0, 0, 0

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by