Clearing Variables From Memory MATLAB App Designer

6 views (last 30 days)
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

Answers (1)

Benjamin Kraus
Benjamin Kraus on 30 Jan 2017
Edited: Benjamin Kraus on 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 Comments
Karl Joseph RIZZO
Karl Joseph RIZZO on 20 May 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
ARP
ARP on 10 Jan 2023
Just give app.FMax an empty value, app.FMax=[];

Sign in to comment.

Categories

Find more on Entering Commands in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!