Add and delete Line and port
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Laurensius Christian Danuwinata
le 15 Fév 2016
Commenté : Laurensius Christian Danuwinata
le 24 Fév 2016
Hello, I have a popup-parameter in a Block Mask. And if an element from the list in popup chosen, the add_line and add_block should be execute. Then, if I choose new element, the old add_line and _block should be deleted and the new add_line and _block will be added. I can use it separately, but how can I write it just in one code? Thanks :D
0 commentaires
Réponse acceptée
Arnab Sen
le 22 Fév 2016
Hi Laurensius,
My understanding from the question is that you would like to perform different action when the popup list element is chosen for the first time than when the list element is chosen for the second time.
We can use 'persistent' variable for this purpose which holds the value between the function calls (Similar to 'static' variable in C). Based on the value of the persistent variable you may take different action as per required.
As an illustration, you may consider the following code in the callback of the particular popup:
b=valueOfPersistent;
if(b==1)
% the add_line and add_block code
disp('b==1');
else
%Code to delete the old add_line and _block and add new add_line and _block
disp(b);
end
And write the function 'valueOfPersistent' as follow:
function b=valueOfPersistent
persistent a;
if isempty(a)
a=1;
end
b=a;
a=a+1;
end
Here the function initializes the variable 'a' only once and increment the values each time the function is called from the callback and returns the latest value.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Programmatic Model Editing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!