How to store data without deleting previous one

7 vues (au cours des 30 derniers jours)
María Pérez Fernández
María Pérez Fernández le 15 Oct 2022
Modifié(e) : Voss le 24 Nov 2022
Hello,
I'm writing a program using App Designer that allows you to select a ROI using drawfreehand in a picture, then switch to the next picture using a "NEXT" button and draw over it again. For the drawfreehand function I have another button named ('DRAW').
I need to store the binary masks of the selected ROIs so I can use them later, but when I try to do it the program only saves the one from the last picture and deteles the previous ones.
How can I solve this?
Here is my code:
function NEXT(app, event)
%this function works fine to switch to the next image
k=length(app.complete);
if app.num<k
app.num=app.num + 1;
end
ISig = dicomread(app.complete{app.num});
imshow(ISig,[],'Parent',app.UIAxes);
function DRAW(app, event)
contE(app.num)=drawfreehand(app.UIAxes,'color','white');
mask{app.num}=createMask(contE(app.num));
save mask.mat mask
% app.num is a property that indicates de index of the image displayed and
% k represents the number of images loaded
  4 commentaires
Jan
Jan le 16 Oct 2022
mask{app.num} = createMask(contE(app.num));
save mask.mat mask
This appends a new cell element to mask and stored the complete arrays. This should work and loading mask.mat should contain all stored masks.
So maybe you are not using the current mask.mat file? You did not provide an output folder in the save command. Safer:
save(fullfile(yourOutputfolder, 'mask.mat'), 'mask');
Of course, now you have to define yourOutputfolder accordingly.
María Pérez Fernández
María Pérez Fernández le 23 Nov 2022
Hello,
I have done this but when I load mask.mat it only contains the last mask created, and all the other entrys are zero.
Thank you very much

Connectez-vous pour commenter.

Réponse acceptée

Voss
Voss le 23 Nov 2022
mask is a variable that only exists in the workspace of the DRAW function. In other words, each time DRAW is executed, a new mask variable is created and saved to the mat file.
To save the values of mask from multiple executions of DRAW, you can make mask an app property.
  2 commentaires
María Pérez Fernández
María Pérez Fernández le 24 Nov 2022
Modifié(e) : María Pérez Fernández le 24 Nov 2022
Thank you very much, It works now!
Voss
Voss le 24 Nov 2022
Modifié(e) : Voss le 24 Nov 2022
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Author Block Masks dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by