Numbering images using function 'websave'.
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi
I created a cell (10 x 1) and stored 10 web URLs in the cell.
The URL would look something like 'http://juliandance.org/wp-content/uploads/2016/01/RedApple.jpg'
I would like MATLAB to read each line of URL in the cell and try to save it as a .jpg file using function 'websave'.
However, not all 10 URLs are valid URLs. Some of it can be invalid and does not lead to any image.
What I would like to do is:
Try to save the first URL, if it can be saved as a .jpg file, name it '01.jpg'. Then move on to the second URL, if it can be saved, name it '02.jpg'; if it can't be saved, move on to the third URL, if it still can not be saved, move on to the fourth URL...and so on and so forth.
If out of 10 URLs it only successfully saved 5 images, regardless the 5 working URLs might be the 1st,3rd,5th,7th and 9th URL, I would still like to name the image in a continuous number from 1-5, rather name them 01.jpg, 03.jpg, 05.jpg, 07.jpg and 09.jpg.
So what is the logic relationship between the URL number and the image number?
Many thanks!
댓글 수: 0
채택된 답변
Rik
2017년 11월 16일
편집: Rik
2017년 11월 16일
filenamecounter=0;
for n=1:10
try
filenamecounter=filenamecounter+1;
filename=sprintf('%s%02d.jpg',explicit_path,filenamecounter);
%call to websave here
catch
filenamecounter=filenamecounter-1;%undo increment on error
end
end
Ideally you would also do some error checking by looking at the exception, so you can verify that it is indeed the error you expected.
댓글 수: 3
Rik
2017년 11월 16일
Yes, you are right. These are the type of mistakes you will keep making if you want to go too fast. I'll edit my answer.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!