Why can't I enter any number that is not a one digit number on my UITable?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Giulia Di Giorgio
il 12 Mar 2023
Commentato: Giulia Di Giorgio
il 12 Mar 2023
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1321675/image.jpeg)
%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 Commento
Walter Roberson
il 12 Mar 2023
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.
Risposta accettata
Walter Roberson
il 12 Mar 2023
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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!