How to enter GUI user input better?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am not very good at matlab but I am trying to write a code that takes a folder of images and allows a user to pull out any increment of images into a new folder (for DIC analysis). I would like to add a button for the user to press to say I'm done and submit their input. As of now, in the gui, you have to press enter to submit the last edit box. Any other advice would be appreciated. I found using the GUIDE code difficult.
%In order to work the image files of interest must be in the current
%path/directory. They must be in the .jpg format.
f= figure;
uicontrol(f,'style', 'text','string', 'Enter Index','position', [65,355,100,20]);
cinput = uicontrol(f,'style', 'edit','String','10','position', [100,325,30,30],'callback','c = get(cinput);C=c.String;I=str2num(C);');
uicontrol(f,'style', 'text','string', 'Enter New Folder Name','position', [300,355,120,20]);
binput = uicontrol(f,'style', 'edit','string', 'NewFolder123','position', [260,325,200,30],'callback','b = get(binput);B=b.String;');
uicontrol(f,'style', 'text','string', 'Enter New Folder Destination','position', [205,255,150,20]);
bdinput = uicontrol(f,'style', 'edit','string', 'C:\Users\crtaylor\Desktop\','position', [100,225,360,30],'callback', 'bd = get(bdinput);BD=bd.String;');
imagefiles = dir('*.jpg');
nfiles = length(imagefiles);
for ii=1:nfiles
currentfilename = imagefiles(ii).name;
currentimage = imread(currentfilename);
images{ii} = currentimage;
end
for jj = 1:I:nfiles
bdtotal = strcat(BD,B);
bestdirectory = bdtotal;%choosen by user
mkdir(bestdirectory);
j=['Image_S001_' num2str(jj-1,'%04d') '.jpg'];
fulldestination = fullfile(bestdirectory,j); %name file relative to that directory
q=images{jj};
imwrite(q, fulldestination); %save the file there directory
end
2 Commenti
Paolo
il 5 Giu 2018
Modificato: Paolo
il 5 Giu 2018
I would like to add a button for the user to press to say I'm done and submit their input.
How about having another uicontrol element for executing that snippet of code? You can use a button by specifying 'Style' to 'pushbutton'.
An example:
btn = uicontrol(f,...
'String','Press me',...
'Style','pushbutton',...
'Position', [35,255,131,35],...
'Callback',@btnpress);
function btnpress(source,value)
%insert your code here.
end
Risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!