Reputation: 7577
I am new on matlab and I don't know many things at the moment.
I have a script which create more than 100 figures. I want to save those figures in 3 different folders. Here is my code until now:
pridir='C:\Users\tasos\Desktop\folder';
figtxt1='folder1';
figtxt2='folder2';
figtxt3='folder3';
yM = load('pathtomydata');
[n,m]=size(yM);
maxtau2 = 10;
alpha = 0.05;
zalpha = norminv(1-alpha/2);
p=6;
for i=1:m-1
for j=i+1:m
figure()
y1V=yM(:,i);
y2V=yM(:,j);
plot(y1V,'b')
hold on
plot(y2V,'r')
legend(sprintf('text= % d',i),sprintf('text= % d',j))
title('My Title')
printto = sprintf('%s%d\\text%d and %d.jpg',pridir,i,i,j);
print('-djpeg90',printto)
close(gcf)
end
end
If I left my code like this, all the figures created but they didn't save on folders. If I remove the "%" from the last two lines, I have the following error
Error using name (line 103)
Cannot create output file 'C:\Users\tasos\Desktop\folder1\text1 and 2.jpg'
Error in print (line 206)
pj = name( pj );
Error in test (line 25)
print('-djpeg90',printto)
P.S. I am using the R2012b version
Upvotes: 0
Views: 1976
Reputation: 3
I think matlab changed the code for writing a folder with the 2013 version.
I changed 'XX\YY\ZZ.pjg' To: 'XX/YY/ZZ.pjg'
And it worked for me, strangely.
Upvotes: 0
Reputation: 10676
Avoid eval()
!
Define one generic print directory:
pridir = 'C:\Users\***\Desktop\fold';
Then inside the inner loop:
printto = sprintf('%s%d\\figuretext %d and %d.jpg',pridir,i,i,j);
print('-djpeg90',printto)
where printto
will be something like:
C:\Users\***\Desktop\fold1\figuretext 1 and 3.jpg
Also, you might want to close the figure after the print: close(gcf)
.
NOTE: the directories where you're gonna save the files should already exist, otherwise create them with mkdir()
before saving any pictures.
Upvotes: 1