APP DESIGNER: Issue with using properties between callback functions.
조회 수: 3 (최근 30일)
이전 댓글 표시
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
Adam Danz
2022년 2월 10일
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.
채택된 답변
Cris LaPierre
2022년 2월 10일
편집: Cris LaPierre
2022년 2월 10일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 3-D Volumetric Image Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!