hey, I wrote a code to save a few images in a for loop in a cirtin folder,it won't work,please help
for beta=-1:1
...
...
...
xx=sprintf('C:\Users\Sagipc\Desktop\ImageLibrary\beta%g.jpg',beta);
imwrite(pic1,xx,'jpg');
end

 Réponse acceptée

Star Strider
Star Strider le 9 Sep 2014

0 votes

Simply stating the problem as ‘it won’t work’ doesn’t tell us much.
It looks as though it’s writing ‘pic1’ to every file you create. I would assume you intend a different result.
What are your image file names? How would you want to save them?

5 commentaires

Sagi
Sagi le 9 Sep 2014
i want it to write for each of the loop indexes ,the image name as 'beta-1','beta0',beta1'. pic1 is an image that changes with every differet index of the loop,I didn't write because it isn't importent. my main goal is to save each pic1 in:C:\Users\Sagipc\Desktop\ImageLibrary with the name 'beta(index)',as a jpg. the error message that i get is:
Warning: Invalid escape sequence appears in format string. See help sprintf for valid escape sequences. > In Lipson3Improved at 21 ??? Error using ==> imwrite at 453 Can't open file "C:" for writing. You may not have write permission.
Error in ==> Lipson3Improved at 22 imwrite(pic1,xx,'jpg');
You have to use double backslants ‘\\’ in fprintf and sprintf to (1) not have them interpreted as control sequences by the print functions, and (2) get them to print out as single backslants ‘\’:
beta = 10; % Arbitrary
xx=sprintf('C:\\Users\\Sagipc\\Desktop\\ImageLibrary\\beta%g.jpg',beta);
produces:
C:\Users\Sagipc\Desktop\ImageLibrary\beta10.jpg
and no errors.
Image Analyst
Image Analyst le 9 Sep 2014
Or just use forward slashes . Windows is perfectly happy to work with forward slashes. It figures out what you meant just fine.
Sagi
Sagi le 9 Sep 2014
that was very helpful, thank u heaps!
Star Strider
Star Strider le 9 Sep 2014
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by