App Designer and external function

조회 수: 1 (최근 30일)
darkphotonix
darkphotonix 2020년 6월 8일
답변: darkphotonix 2020년 6월 8일
Im having issues with running my app. The m file alone works but, when I attempt to convert it to the app, its throwing errors just in the app. My code involves matrixes and vectors. Error is at the external function ElementofFasteners, I have commented the lines for a visual representation of what I am seeing. Like I said, this works as a standalone m. file without the app. What am I missing and are the app.inputs creating different variables or... need a bit of help
Error using /
Matrix dimensions must agree.
Error in Fasteners (line 29)
c1=(((t1 + t2)/(2*D))^a);
% Button pushed function: SolveButton
function SolveButtonPushed(app, event)
%Solve Everything here
app.FastF1.Value = numfast(app.nf); % numfast external function-works
app.FastF2.Value = app.E1;
app.FastF3.Value = app.d3;
app.nnel = 3 * app.nf;
app.nnode = 2 + (2 * app.nf);
app.sdof = app.nnode * app.ndof;
kk=zeros(app.sdof,app.sdof);
index=zeros(app.nel*app.ndof,1); %orange underline (use Plate(app.,..
for iel=1:app.nnel
if iel <= (app.nnel - app.nf)
[k]=Plate(app.E1,app.w,app.t1,app.L); % Plate external function-orange underline (use Plate(app.,..
index = ElementdofPlate(iel,app.nel,app.ndof,app.nf);
else
if app.count == 1
d = app.d2;
app.count = app.count + 1;
elseif app.count == 2
d = app.d3;
app.count = app.count + 1;
elseif app.count == 3
d = app.d4;
app.count = app.count + 1;
elseif app.count == 3
d = app.d5;
app.count = app.count + 1;
elseif app.count == 4
d = app.d6;
app.count = app.count + 1;
else
d = app.d1;
app.count = app.count + 1;
end
[k]=Fasteners(app.E1,app.E2,app.E3,app.t1,app.t2,d); % Fastners external function-orange underline (use Fasteners(app.,..
index = ElementdofFasteners(iel,app.nf); % external function-orange underline (use Elemt..(app.,..
end
kk=Assemble(kk,k,index); % external function-orange underline (use Elemt..(app.,..
end
%
% Applying the Boundary conditions
[kk] = constraints(kk,1) ;% external function-orange underline (use Elemt..(app.,..
[kk] = KRED(kk,app.nnode);% external function-orange underline (use Elemt..(app.,..
[uu] = Displacements(kk,app.P,app.nnode); % external function-orange underline (use Elemt..(app.,..
app.FastF4.Value = uu(1);

채택된 답변

darkphotonix
darkphotonix 2020년 6월 8일
Check the order of the callbacks

추가 답변 (1개)

Cris LaPierre
Cris LaPierre 2020년 6월 8일
편집: Cris LaPierre 2020년 6월 8일
You do not call a function named ElementofFasteners in the code you have shared.
The error message suggests to me the problem is that your inputs in the app are different from what they are when you call the function in MATLAB. Since we have no information on what they should be, I'd suggest starting to debug by using breakpoints and comparing the inputs in the app to what you expect them to be.
I'd suggest paying close attention to the dimensions. It might be that the function was designed for the inputs to be column vectors, but in the app they are created as a row vectors.
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2020년 6월 8일
Ah, sorry. I searched for it but it obviously didn't find this.
iel is an integer, but I don't know what app.nf is.
What is the calling syntax of ElementdofFasteners? Can you share the function declaration line? Do you perhaps need to pass the inputs in as a 1x2 vector? If so, enclose the inputs in square brackets.
index = ElementdofFasteners([iel,app.nf]);
darkphotonix
darkphotonix 2020년 6월 8일
I figured it out, it was actually quite simple. I forgot matlab reads line by line even with the functions and the solve button was before the the variable input for app.nf, thus nf never existed. After, reordering the callbacks it worked out nicely!
Thanks for your help Cris.

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

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by