필터 지우기
필터 지우기

Sharing variables between unicontrol function and WindowScrollWheelFcn

조회 수: 3 (최근 30일)
Hello,
I wrote a little program to read dicom files and then show them by using scroll mouse function. The program works well. However I would like to open another folder with dicom images and then read it again without closing the program. And here I have a problem because I do not know how to pass variables from unicontrol function to WindowScrollWheelFcn. Below I present my program.
function ct_scans_read
clear all
f = figure('Name','Image diacom file read','Position',[600 300 900 650]);
h = axes('Parent',f,'units','pixels','Position',[50 100 512 512]);
set(f, 'WindowScrollWheelFcn',@figScroll);
text1=uicontrol('Parent',f,'Style','text','String','Path to directory','Position',[100 60 160 25],'BackgroundColor','white','FontSize',12,'FontWeight','bold');
pathr= uicontrol('Parent',f,'Style', 'edit', 'String','C:\CT Images\','Position', [20 30 850 20],'BackgroundColor','white','FontSize',10,'FontWeight','bold');
name_path = get( pathr , 'string' );
dirOutput = dir(name_path);
row = size(dirOutput,1);
for i = 3:row
nname = [name_path dirOutput(i).name];
info = dicominfo(nname);
dicom_images(:,:,i-2) = dicomread(info);
end
h = imshow(dicom_images(:,:,1));
function figScroll(src,callbackdata)
if callbackdata.VerticalScrollCount > 0
if i >= row-2;
i = row-2;
else
i=i+1;
end
h = imshow(imadjust(uint16(dicom_images(:,:,i)),[1923/65535 1924/65535],[]));
elseif callbackdata.VerticalScrollCount < 0
if i <= 1;
i = 1;
else
i=i-1;
end
h = imshow(imadjust(uint16(dicom_images(:,:,i)),[1923/65535 1924/65535],[]));
end
end
end
If I do this way I have an error: Error: File: ct_scans_read.m Line: 39 Column: 17 "i" previously appeared to be used as a function or command, conflicting with its use here as the name of a variable. A possible cause of this error is that you forgot to initialize the variable, or you have initialized it implicitly using load or eval.
function ct_scans_read
clear all
f = figure('Name','Image diacom file read','Position',[600 300 900 650]);
h = axes('Parent',f,'units','pixels','Position',[50 100 512 512]);
set(f, 'WindowScrollWheelFcn',@figScroll);
text1=uicontrol('Parent',f,'Style','text','String','Path to directory','Position',[100 60 160 25],'BackgroundColor','white','FontSize',12,'FontWeight','bold');
pathr= uicontrol('Parent',f,'Style', 'edit', 'String','C:\CT Images\','Position', [20 30 850 20],'BackgroundColor','white','FontSize',10,'FontWeight','bold');
set(pathr, 'callback', {@unicontrol,h})
function f=unicontrol(hObject, eventdata, f)
name_path = get( pathr , 'string' );
dirOutput = dir(name_path);
row = size(dirOutput,1);
for i = 3:row
nname = [name_path dirOutput(i).name];
info = dicominfo(nname);
dicom_images(:,:,i-2) = dicomread(info);
end
h = imshow(dicom_images(:,:,1));
i=row-2;
end
function figScroll(src,callbackdata)
if callbackdata.VerticalScrollCount > 0
if i >= row-2;
i = row-2;
else
i=i+1;
end
h = imshow(imadjust(uint16(dicom_images(:,:,i)),[1923/65535 1924/65535],[]));
elseif callbackdata.VerticalScrollCount < 0
if i <= 1;
i = 1;
else
i=i-1;
end
h = imshow(imadjust(uint16(dicom_images(:,:,i)),[1923/65535 1924/65535],[]));
end
end
end
Any help will be appreciated. Thank you.
  댓글 수: 4
Gabe
Gabe 2023년 8월 8일
Just curious, what seemed to be the problem?
Walter Roberson
Walter Roberson 2023년 8월 8일
The user tried to use the variable i as a shared variable in nested functions. However, shared variables need to be defined before a nested function that uses the shared variable. The user needed to initialize i before definining function f=unicontrol(hObject, eventdata, f)

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

채택된 답변

Walter Roberson
Walter Roberson 2016년 2월 16일

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scripts에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by