Azzera filtri
Azzera filtri

How can I change the folder to be browsed upon when pushbutton is clicked?

1 visualizzazione (ultimi 30 giorni)
Hi, I was wondering if you could help me change the folder when the pushbutton is clicked?
For example, my current folder is C:\Users\Valued User\Documents\5th year, 2nd term\THESIS on which all my files are on.
However, I want it that when I push my "load image" button in my gui, the browser would go directly to another folder inside my current folder which is C:\Users\Valued User\Documents\5th year, 2nd term\THESIS\imagesss.
In short, I want the browser to open directly in a specific folder when that button is clicked. Is there a good way to do this? Here's the code which is available in the internet by the way:
% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %cd('C:\Users\Valued User\Documents\5th year, 2nd term\THESIS') %pwd('C:\Users\Valued User\Documents\5th year, 2nd term\THESIS\imagesss')
%----------> here we load image
global im im2
[path,user_cance]=imgetfile();
if user_cance
msgbox(sprintf('Error'),'Error','Error');
return
end
im=imread(path);
im=im2double(im); %converts to double
im2=im; %for backup process :)
axes(handles.axes1);
imshow(im);

Risposta accettata

Niklas Nylén
Niklas Nylén il 14 Gen 2014
Modificato: Niklas Nylén il 14 Gen 2014
If it works like uigetfile, you should be able to pass the desired folder as an argument,
[path,user_cance]=imgetfile('C:\Users\Valued User\Documents\5th year, 2nd term\THESIS\imagesss\');
If this does not work you may need to go around it by changing the folder temporarily.
workPath = pwd;
cd('C:\Users\Valued User\Documents\5th year, 2nd term\THESIS\imagesss')
[path,user_cance]=imgetfile();
cd(workPath)
  2 Commenti
Erika
Erika il 16 Gen 2014
I tried putting it but still it opens not in the destination i want it to go to :(
global im im2
workPath = pwd;
cd('C:\Users\Valued User\Documents\5th year, 2nd term\THESIS\imagesss')
[path,user_cance]=imgetfile();
cd(workPath)
if user_cance
msgbox(sprintf('Error'),'Error','Error');
return
end
im=imread(path);
im=im2double(im); %converts to double
im2=im; %for backup process :)
axes(handles.axes1);
imshow(im);
Niklas Nylén
Niklas Nylén il 16 Gen 2014
Are you sure that the path is correct? Try running just the cd(...) line to check if it works.
Otherwise, do you know the file format of the file you will open? In that case, try using uigetfile instead of imgetfile. For a png-file, it would look like this:
[FileName,PathName] = uigetfile('C:\Users\Valued User\Documents\5th year, 2nd term\THESIS\imagesss\*.png')
user_cance = ~ischar(FileName);
if user_cance
...
end
path = fullfile(PathName,FileName);

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps 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