How to enter GUI user input better?

2 visualizzazioni (ultimi 30 giorni)
Caitlin Taylor
Caitlin Taylor il 5 Giu 2018
Commentato: Caitlin Taylor il 6 Giu 2018
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
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
Caitlin Taylor
Caitlin Taylor il 6 Giu 2018
I am just not sure what callback to use to save the responses in the work space (I look up other answers and they take me to GUIDE stuff, which confuses me) and close the figure (maybe closereq). If you can point me to a certain function that triggers to save input response, like how the enter button does, that would be great. When I tried to use
assignin('base','myVar',file_path)
in the callback it didn't work because of the apostrophe's. So basically I am at a loss, and I have no idea how to save or set how a users response is set and accepted.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Images in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by