Cannot convert EditField(text) into arrays or matrix
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I try to make a project for colledge. My task is to enter in the EditFields(Text) two separate values for the 3 examples below. If it's a scalar, I have to enter 2 numbers, if it's a vector(array) to enter 2 arrays and if it's a matrix, to enter 2 matrixes. Everything went well until I try to enter 2 arrays or matrixes in the EditFields(Text). I tried different ways like [1, 2, 3] or [1 2 3] or 1 2 3 etc, but everytime I got either the error 'Error setting property 'Data' of class 'Table':
Data within a cell array must have size [1 1]' or 'Error setting property 'Data' of class 'Table': Values within a cell array must be numeric, logical, or char' . The results should be shown into the table from bottom right. I tried to convert the values like this:
newRow = {selectedFunction, result};
if isnumeric(result)
newRow{2} = result;
elseif ischar(result)
newRow{2} = {result};
else
uialert(app.UIFigure, 'Eroare: Tip de date neacceptat pentru adăugarea la tabel!', 'Eroare', 'Icon', 'error');
return;
end
app.ResultTable.Data = [app.ResultTable.Data; newRow];
Any suggestions? It's pretty urgent, my deadline is in 2 days to present the project. Many thanks!
I tried to 

0 Commenti
Risposte (1)
Voss
il 28 Gen 2024
Modificato: Voss
il 30 Gen 2024
Here (attached and reproduced below) is a simple GUI where you can enter scalars, vectors, or matrices, and their sum will be shown in a new row in the table. Note that the dimensionality of the inputs does not have to be explicitly specified (e.g., with a radiobutton selection) because the program works the same whatever you enter. You can run this program yourself and see how it works, and adapt your app as needed.
function array_plus_table_demo()
f = uifigure('AutoResizeChildren','off');
ed1 = uieditfield(f,'text');
ed2 = uieditfield(f,'text');
btn = uibutton(f,'Text','Go','ButtonPushedFcn',@cb_go);
t = uitable(f,'Data',cell(0,2),'ColumnName',compose('Column %d',[1 2]),'RowName',{});
f.SizeChangedFcn = @scf;
scf()
function cb_go(~,~)
val1 = str2num(ed1.Value,'Evaluation','restricted');
val2 = str2num(ed2.Value,'Evaluation','restricted');
if ~isequal(size(val1),size(val2))
uialert(f,'Inputs must be the same size','Error','Icon','error');
return
end
str = mat2str(val1+val2);
t.Data(end+1,:) = {'plus',str};
end
function scf(~,~)
ppos = f.Position;
space = 10;
wh = [85 26];
xy = ppos([3 4])./[4 2]-wh./[2 1]-[0 space];
dy = wh(2)+space;
ed1.Position = [xy wh];
ed2.Position = [xy wh]-[0 dy 0 0];
btn.Position = [xy wh]-[0 2*dy 0 0];
wh = max(0,ppos([3 4])./[2 1]-2*space);
t.Position = [ppos(3)-space-wh(1) space wh];
end
end
Vedere anche
Categorie
Scopri di più su Data Type Identification 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!
