MATLAB GUI does not work for others
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi there,
I created a MATLAB GUI as a task at my university. The problem is, that if perfectly works when I am starting it by pressing the "Calculate"-Button on my Interface, but for my friend it somehow does not work. First I thought that the problem was that he needed to Install a special toolbox, but even now it is showing errors.
I coded the program in MTALAB R2021a and he even upgraded his MATLAB R2017 to the newest one, but that did not help.
Mayba anybody knows the origin of the mistake. My complete code is in the file "bachelor", "arclength" is a tool that is used in the code.
I tried using the online Version of MATLAB, but the same errors occurred. I can't think of any reason why this would happen.
The errors shown in the command window are shown below:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right
side.
Error in sym/privsubsasgn (line 1168)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in indexing (line 999)
C = privsubsasgn(L,R,inds{:});
Error in bachelor>pushbutton_Callback (line 60)
tnum(i) = vpasolve(snum(i)==s(t),t);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in bachelor (line 16)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)bachelor('pushbutton_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
I really hope, that somebody can help me.
Thanks in advance!
2 comentarios
Image Analyst
el 17 de Jul. de 2023
I couldn't run it either. It requires the Symbolic Toolbox. You forgot to add that when you posted, so I'll add it to the product list at the right so no one else wastes their time.
Respuestas (3)
Walter Roberson
el 18 de Jul. de 2023
The work-around is to change
tnum(i) = vpasolve(snum(i)==s(t),t);
to
tnum(i) = vpasolve(snum(i)-s(t),t);
snum(i) happens to be 0 the first time around, so the original equation is trying to solve 0 == s(t) . For reasons that are not currently clear to me, vpasolve() is happy to deal with vpasolve(s(t)) but not with vpasolve(s(t)==0)
K>> simplify(snum(i)==s(t))
ans =
4*5^(1/2)*log((5*t^2 - 2*t + 1)^(1/2) + (5^(1/2)*(5*t - 1))/5) + 50*(t/2 - 1/10)*(5*t^2 - 2*t + 1)^(1/2) == 4*5^(1/2)*log(1 - 5^(1/2)/5) - 5
K>> simplify(snum(i)-s(t))
ans =
16*5^(1/2)*log(1 - 5^(1/2)/5) - 16*5^(1/2)*log((5*t^2 - 2*t + 1)^(1/2) + (5^(1/2)*(5*t - 1))/5) - 200*(t/2 - 1/10)*(5*t^2 - 2*t + 1)^(1/2) - 20
Notice the simplify() of the == form results in an == with a non-zero comparison. If vpasolve() is internally doing that kind of simplify() and then applying vpa() to the two sides, then the numeric solution is not at exactly 0 because of round-off error. I do not know if that has anything to do with the problem.
Anyhow, vpasolve(snum(i)==s(t),t) is failing even if you give it the hint of 0 (the actual solution) whereas vpasolve(snum(i)-s(t),t) works fine.
3 comentarios
Walter Roberson
el 18 de Jul. de 2023
When you solve or vpasolve an expression that has no relation operators then it is implied that you are asking to solve the expression == 0. But that also means that if you have A==B that you can subtract B from both sides to get A-B==B-B which is A-B==0 and then take advantage of the implied ==0 by asking to solve A-B. So in theory you are not changing the equation. In practice in this case vpasolve is treating the two cases differently, and it is not clear why that is the case.
Rafael
el 20 de Jul. de 2023
The root cause is that whereas the "int" call returned an unevaluated expression in R2021a, "int" is able to solve this in later releases and returns a piecewise function. Unfortunately, "vpasolve" has problems with this function. So, the workflow breaks because int in the 23a version or later evaluates the integral, but the "vpasolve" function cannot calculate a solution for this function. As a workaround, you can use the vpaintegral function or set “Hold”, true in the int command.
1 comentario
Walter Roberson
el 20 de Jul. de 2023
... but this does not answer to the question of why vpasolve(snum(i)==s(t),t) fails but vpasolve(snum(i)-s(t),t) succeeds, since piecewise() is involved either way.
Harald
el 17 de Jul. de 2023
Editada: Harald
el 17 de Jul. de 2023
Hi Tim,
When I open the GUI and hit calculate without changing any setting, it works fine for me in R2021a but I can reproduce the error in R2023a.
In R2023a, the problem is that vpasolve cannot find a solution, and you'd try to assign an empty array to a value. Since vpasolve was able to find a solution in R2021a and a plot of s(t) shows that the function is well-behaved, this may be a bug in vpasolve in R2023a and I therefore suggest that you contact the Technical Support of MathWorks.
Best wishes,
Harald
3 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!