Azzera filtri
Azzera filtri

APP DESIGNER: Issue with using properties between callback functions.

3 visualizzazioni (ultimi 30 giorni)
Hi,
I am working on an image segmentation GUI. When I load in my volume, I am storing it in a property I made called "app.volume". I do this as I want to use the volume between callback functions. I load in my volume in one callback function and assign app.volume the data. However, when I move onto the following callback function, in which I need to use the app.volume data, I am not able to retrieve it.
I am not sure why this is happening, and I need to be able to work with the volume between various callback functions. Any advice?
  17 Commenti
Adam Danz
Adam Danz il 10 Feb 2022
Ah, I missed that. That clears your app object from the function workspace so when you assign data to app.volume, "app" becomes a structure variable which is cleared when the SelectDICOMDirectoryButtonPushed function ends. The "app" object still exists outside of the function but its values are gone which is why it retains the [0,0] size in the next callback function.
Lesson learned: there is rarely a need to clear variables within function workspaces. One exception is if a variable size is large and you no longer need it and want to reduce memory.
Anupreet Singh
Anupreet Singh il 10 Feb 2022
Hi Adam,
Yes that makes a lot of sense. Thank you so much for your help.

Accedi per commentare.

Risposta accettata

Cris LaPierre
Cris LaPierre il 10 Feb 2022
Modificato: Cris LaPierre il 10 Feb 2022
I think I have discovered the issue. In the SelectDICOMDirectoryButtonPushed() callback function, I have the following line at the beginning of the function:
clc; clearvars; close all; % to clear anything that may have previously been loaded
Ah, that's it.
That code clears the input variable app from the function workspace, so when you assign img to app.volume, you do so to a local variable, not the app property. Once the callback function finishes executing, that local variable is deleted. When you then call ViewDICOMSeriesButtonPushed, it passes in app without the volume property being populated.
You are in a function, so it is completely unnecessary to use any of that code. Your function starts with a brand new workspace with just the input variables. You do not need to clear, close, or clc anything.

Più risposte (0)

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by