Clearing Variables From Memory MATLAB App Designer
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
So I'm running into a weird error when trying to run a function multiple times in MATLAB's App Designer. I attempt to clear the variables using the code below, but I am still running into the "subscripted assignment dimension mismatch" as it tries to access part of app.layerIndex that no longer exists. Is there some other way to clear the variables that is different?
if true
removeVars = {'app.labeledClumped','app.cropProperties','app.numberOfCrops','app.colorBlobImages','app.cropArea','app.cropPixelList','app.layerIndex','app.cropRGB','app.cropMeanRGB','app.exportData'};
clear(removeVars{:});
end
0 commentaires
Réponses (1)
Benjamin Kraus
le 30 Jan 2017
Modifié(e) : Benjamin Kraus
le 30 Jan 2017
The app variable in App Designer is an object. From your description it sounds like what you are calling variables are really properties on the object. Because app is an object, the values of the properties are persistent as long as your application is open. You cannot clear those properties using clear.
Instead of clearing the properties using clear, you can just set the values to an empty value. However, if you are not using the values across multiple calls to the function it is easier to just create and use a variable within the function. For example, take the following function that could be added to an app:
function myFunc(app)
% The variable labeledClumped will be erased between
% executions of myFunc.
labeledClumped = 10;
% The variable numberOfCrops will be erased between
% executions of myFunc.
numberOfCrops = 10;
% If LatestOutput is a property of the app, it will
% persist across calls to myFunc.
app.LatestOutput = labeledClumped * numberOfCrops;
% If NumTimesMyFuncRun is a property of the app, you
% can read and modify every time you call myFunc.
app.NumTimesMyFuncRun = app.NumTimesMyFuncRun + 1;
end
2 commentaires
Karl Joseph RIZZO
le 20 Mai 2022
Hello Benjamin,
I have kind of the same issu but setting values to empty values lead to
"Unable to perform assignment because the size of the left side is 0-by-1 and the size of the right side is 29-by-1." error.
cla(app.UIAxes)
clearvars app.FMax(:,:);
[app.FMax(:,2),app.FMax(:,1)] = findpeaks(app.DATAKJ(1:end-1,2),app.DATAKJ(1:end-1,1),'MinPeakHeight',app.DeltaPeackF,'MinPeakDistance',app.DeltaPeackt,'Annotate','extents','WidthReference','halfheight');%seuil à 3% du pique max
as the app lets the user run several peak detection with different MinPeakHeight, size of A=findpeaks(B) is not consistent.
Regards
Voir également
Catégories
En savoir plus sur Entering Commands dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!