Clearing Variables From Memory MATLAB App Designer

조회 수: 12 (최근 30일)
Coby Allred
Coby Allred 2017년 1월 30일
댓글: ARP 2023년 1월 10일
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

답변 (1개)

Benjamin Kraus
Benjamin Kraus 2017년 1월 30일
편집: Benjamin Kraus 2017년 1월 30일
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
Karl Joseph RIZZO
Karl Joseph RIZZO 2022년 5월 20일
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 2023년 1월 10일
Just give app.FMax an empty value, app.FMax=[];

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

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by