using external matlab file variables in app desighner

1 visualización (últimos 30 días)
fima v
fima v el 29 de En. de 2022
Editada: dpb el 30 de En. de 2022
Hello , I have written matlab code in *.M matlab file.
this matlab code has many variables and expressions.
i want to use this code in the Matlab file in my APP(i am new to matlab apps)
is there some example i could use to undesrtand this issue?
Thanks.
  5 comentarios
fima v
fima v el 29 de En. de 2022
is there some example i could follow?
thanks

Iniciar sesión para comentar.

Respuestas (2)

dpb
dpb el 29 de En. de 2022
Editada: dpb el 30 de En. de 2022
"is there some example i could follow?" -- @fima v
function UpdateButtonPushed(app, event)
app.UpdateButton.Enable='off'; app.UpdateButton.Text="Working"; app.UpdateButton.FontColor='r';
app.QuitButton.Enable='off';
drawnow nocallbacks
if ~isfile(app.billQualFile)
h=errordlg([app.billQualFile "Not Found. Must Set Billing File First."],'modal');
waitfor(h)
app.UpdateButton.Text="Update"; app.UpdateButton.FontColor='k'; app.UpdateButton.Enable='on';
app.QuitButton.Enable='on';
drawnow
return
end
sheets=sheetnames(app.billQualFile);
% ... bunch more error-checking code elided as superfluous...
% probably 100 lines of code, none of which is anything more than more of the same
% of the above if block for all the possible things that could happen...
% insert a progress dialog for grins...
h=uiprogressdlg(app.RestrictedFundsAwardsWorkbookUpdateToolUIFigure, ...
"Title",'Please Standby...',"Message",'Reading Billing',"Indeterminate","on");
% and finally, do the work...
[tBill,tPay]=readBilling(app.billQualFile,app.billSheet,app.billUpdate);
h.Message='Writing Awards';
writeAwards(tBill,tPay,app.year,app.semester,app.awardQualFile,app.awardSheet);
h.Message='Update Complete';
pause(0.5)
close(h)
app.UpdateButton.Text="Update"; app.UpdateButton.FontColor='k'; app.UpdateButton.Enable='on';
app.QuitButton.Enable='on';
drawnow
end
The above is one callback function in an app of mine -- when it finally(!) gets through all the error checking and the boilerplate, it then calls the external functions readBilling and writeAwards to do all the actual work.
As you see, there's nothing special at all in calling the functions; the m files do reside in the local folder where the app code is being built so they are visible, but that's it--using them is no different than using any other MATLAB function. When the app is packaged, the dependency walker finds them and includes them in the needed files section and all is well.
Nota Bene: the reference to the application local variables in the arguments; that's really the only thing at all about it being an application rather than "ordinary" procedural code.
Nota Bene Second: that the reference to the returned variables from readBilling are local variables within the callback function that are passed to writeAwards(); just like regular procedural code, they are local in scope within the function and are destroyed automagically when the function completes.
In this case writeAwards does all the work -- it creates a highly-formatted Excel file which is the end result of the application. If your app needs to compute stuff and do something with it inside the app, then like the helper function readBilling above, it will return those results locally and you do whatever is needed with them -- either in this routine or if they need to be available to other callbacks, then you create application variables for them.
It would seem you're trying to make it harder than it is...

Image Analyst
Image Analyst el 29 de En. de 2022
If it's a script, you can turn that script into a function and call it.
Or you can make it a function and paste it right in to your .mlapp file.
Just make sure you return the variables to the calling routine or else attach them to the app structure so that other functions can see the variables.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by