Hi,
I have used a function like below.
function rough1(src,des)
p = dir(fullfile(src,'*.tif'));
mkdir(des);
....
...
...
end
and in the command window i was calling this
  • src= [uigetdir('')];
  • des = uiputfile;
  • rough1(src,des)I can select any folder for processing. I can select any directory for save and can give a folder name. However; it by default saves in MATLAB. As for example if I want to save this to desktop and select it, it still saves in MATLAB.

 Respuesta aceptada

Geoff Hayes
Geoff Hayes el 4 de Sept. de 2014

1 voto

Siam - uiputfile is used for choosing the filename and directory where you want to save the new file. If you want the path (as well as the file name) you would have to do something like
[filename,pathname] = uiputfile;
But since your are moving/copying multiple files, you don't need to choose a file name. So I think that you want to re-use the call to uigetdir to set the destination folder. Try the following
srcPath = uigetdir('');
destPath = uigetdir('');
rough1(srcPath, destPath)
I tried this, and was able to save all tifs from one directory to a folder on my desktop.

10 comentarios

Siam
Siam el 4 de Sept. de 2014
Editada: Siam el 4 de Sept. de 2014
Thank you for your suggestion.
How to use pathname using [filename,pathname] = uiputfile;
But I can not create a new folder while using destPath = uigetdir(''); A new window opens to select a folder but not to create a new folder.
Either I need to use an existing file I need to right click on the window to create a new file. Pleas do correct me if I am wrong.
Is there any way I can create a new folder using the above code?
Thanks a lot.
Joseph Cheng
Joseph Cheng el 4 de Sept. de 2014
for me uigetdir() opens up the windows folder selection screen which at the top has a button to make a "New folder" under the address bar (windows 7).
Siam
Siam el 4 de Sept. de 2014
Got it. Thanks a lot.
Siam
Siam el 5 de Sept. de 2014
Editada: Siam el 5 de Sept. de 2014
I can create a new folder anywhere and can save the files in that folder. However; as for example, if a folder already exist and some files are there and I want to save new files in that existing folder it replaces all the existing files with the new files if the file names are same.
Is that possible to add something (as for example a number probably or may be a word ) with the new file and save it in the existing folder rather than replacing the old file with same title from that folder?
Any help will be appreciated.
Geoff Hayes
Geoff Hayes el 5 de Sept. de 2014
Editada: Geoff Hayes el 5 de Sept. de 2014
You can use the exist function to see if the file already exists. If it does, then just rename the file
fileName = sprintf('image_%d.jpg',d);
fullFileName = fullfile(folderName,fileName);
fileId = 1;
while exist(fileName,'file')==2
% create the new file name
fileName = sprintf('image_%d_%d.jpg',d,fileId);
fullFileName = fullfile(folderName,fileName);
% increment the unique identifier
fileId = fileId + 1;
end
The above will check for the file named (for example) image_1.jpg in the specified directory. If found, it will check for the file named image_1_1.jpg, image_1_2.jpg, etc. until the loop condition evaluates to false on a file that does not exist in the folder.
EDIT
The condition in the above while loop should be
while exist(fullFileName,'file')==2
Siam
Siam el 5 de Sept. de 2014
Editada: Siam el 5 de Sept. de 2014
I was trying this what you have suggested me.
If the folder in empty it gives a name like image_1_1 instead of image_1. If I try to save again in the same folder it does not change but replaces the old file.
No clue what I was doing wrong.
Look forward to hear some suggestion from you.
Geoff Hayes
Geoff Hayes el 5 de Sept. de 2014
There is a mistake in my above code - I will bold it to indicate the problem. The condition for the while loop should be
while exist(fullFileName,'file')==2
Siam
Siam el 5 de Sept. de 2014
That is what I was looking for. Thanks a lot. Great help.
Siam
Siam el 14 de Oct. de 2014
As for example if my input image is (lets say : image-10-00, image-10-01, image_10_02 >>> now I can save them as process_1, process_2,process_3 serially but not exactly as the same input image title).
Any advice will be appreciated.
Geoff Hayes
Geoff Hayes el 14 de Oct. de 2014
Siam - I'm not really sure what you are asking. As this doesn't really correspond to the original question, you should post a new one. Please make it absolutely clear what you are looking for.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Preguntada:

el 4 de Sept. de 2014

Comentada:

el 14 de Oct. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by