I have a Property in my App Designer defined as ''Index''.
This Property is used in most of my callback functions to access specific values.
However, before start to run any callback function, I need to ''clear'' the value of this Property so that I do not have influence of previous values in the callback I'm current running.
I tried to use
clearvars app.Index
but did not have the expected result.
Any ideas?

 채택된 답변

Adam Danz
Adam Danz 2021년 1월 28일
편집: Adam Danz 2021년 1월 28일

0 개 추천

> I need to ''clear'' the value of this Property so that I do not have influence of previous values in the callback I'm current running
You can clear the content of that property using
app.Index = []; % numeric data
app.Index = {}; % cell arrays
app.Index = ''; % character arrays
app.Index = ""; % strings
% etc...
That can be used as a flag to ignore a section of code,
if ~isempty(app.Index)
% stuff
end
Addendum
To create an empty table
app.Index = table();
To clear a table and maintain the headers
app.Index(:,:) = []; % Preserves the class of each column
% or
app.Index = table([],[],{}); % Creates a new 0x3 table and defines classes for each column

댓글 수: 4

THULYO NEDER
THULYO NEDER 2021년 1월 28일
편집: THULYO NEDER 2021년 1월 28일
Thanks for your reply Adam.
In case I have a table assigned for this property, which is the most recommended to use?
Adam Danz
Adam Danz 2021년 1월 28일
편집: Adam Danz 2021년 1월 28일
If you wanted to replace it with an empty table,
app.Index = table();
If you want to clear the data and maintain the headers,
app.Index = array2table(ones(0,width(app.Index)),'VariableNames', app.Index.Properties.VariableNames);
Both options will pass the isempty test.
THULYO NEDER
THULYO NEDER 2021년 1월 28일
Thanks Adam.
It worked!
Adam Danz
Adam Danz 2021년 1월 28일
편집: Adam Danz 2021년 1월 29일
Thanks for the feedback, @THULYO NEDER
I've updated the answer to provide a better method of clearing a table,
app.Index(:,:) = [];
This method preserves the class of each column.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

태그

질문:

2021년 1월 28일

편집:

2021년 1월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by