Matlab function doesnt run when called from AppDesigner
Show older comments
I have a problem in which if I call a function from Command Window it functions properly, but when I call it from App Designer it says there is a mistake in the matrix multiplication dimensions. I think this is very weird, because if there was a mistake related to a matrix shouldn't it show in both modes??? I've been using it from command line for a while and its been working fine, Im not sure why it doesnt run from AppDesigner.
This is the code :
function [resultCode, resultX1, resultX2, Z] = busquedas_function(Xo, Delta, Iter, Fun)
resultCode = 0;
% 1 = success
% 2 = failed
%input es un comando de solicitud de entrada de datos del usuario.
f=inline(Fun);
Yo=f(Xo);
if Yo==0
fprintf('\n\nSOLUCION:\n');
fprintf ('Xo es raiz\n\n');
else
X1=Xo+Delta;
Cont=1;
Y1=f(X1);
Z=[Cont,Xo,Yo,(Yo.*Y1)];
%Z es una matriz la cual permitira observar lo datos como una tabla a la
%finalizacion del programa
%La sentencia While ejecuta todas las órdenes mientras la expresión sea
%verdadera.
while (((Yo*Y1)>0) & (Cont<Iter ))
Xo=X1;
Yo=Y1;
X1=Xo+Delta;
Y1=f(X1);
Cont=Cont+1;
Z(Cont,1)=Cont;
Z(Cont,2)=Xo;
Z(Cont,3)=Yo;
Z(Cont,4)=Yo*Y1;
%las z son las posiciones asignadas en la tabla a los resultados que se
% observarán
end
if Y1==0
fprintf('\n\nSOLUCION:\n')
fprintf('%g es raiz\n\n',X1)
resultX1 = X1;
resultX2 = X1;
else
if Yo*Y1<0
fprintf('\n\nSOLUCION:\n')
fprintf ('El intervalo que contiene la raíz es[%g,%g]\n\n',Xo,X1)
resultCode = 1;
resultX1 = Xo;
resultX2 = X1;
else
fprintf('\n\nSOLUCION:\n')
fprintf ('Fracaso en %g iteraciones\n\n',Iter)
resultCode = 2;
resultX1 = 0;
resultX2 = 0;
end
end
end
fprintf('TABLA\n\nIteraciones Xo Yo Yo*Y1 \n\n');
disp(Z);
%La funcion disp permite visualizar la tabla, obtenida de los resultados de
%la secuencia while
ezplot(f);
%El comando ezplot permite grafica una función.
end
if I call it from command line it runs correctly

But calling it with same parameters from App Designer brings up this error:
"Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-11.
Error in busquedas_function (line 40)
Z(Cont,3)=Yo;"

5 Comments
Sargondjani
on 14 Nov 2021
The questions is which of the two matrices has the wrong size? The LHS or RHS?
Maybe you can check inside the code where the size of the matrices diverge? (command line versus appdesigner)
Sara Rodriguez
on 14 Nov 2021
Why don't you start by calling it with the exact same values in app designer (-2, 0.5, 20, '3*x*x+5*x+2') and confirm that it's about your arguments and not the fact that it's being called from app designer?
My guess is you're passing in a character and you meant to pass in a number (e.g. '-2' instead of -2) and a str2num will resolve the issue.
Sara Rodriguez
on 15 Nov 2021
Are you sure your editfield values are numbers and not characters that contain numbers? If I do:
h=uieditfield;
And then type the number 0.5 in there, and then do h.Value, I get '0.5' not 5. I think you want str2num (I previously wrote num2str by accident sorry!)
Xo = str2num(app.XoEditField.Value);
Delta = str2num(app.DeltaEditField.Value);
Iter = str2num(app.IteraEditField.Value);
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


