how save produced images in loop

조회 수: 1 (최근 30일)
nadia
nadia 2014년 11월 8일
댓글: Image Analyst 2014년 11월 8일
hi i have a loop and produce blocks 32*32 with zeros now i want to save them in special folder how can i do it?
  댓글 수: 1
nadia
nadia 2014년 11월 8일
편집: nadia 2014년 11월 8일
i use this code
for i=1:4
b=zeros(32,32);
xx=sprintf('F:\b\i%d.bmp',i);
imwrite(b,xx,'bmp');
end
but it says Can't open file "F" for writing. You may not have write permission. please help me

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 11월 8일
Nadia - you are using backslashes in your string which is probably generating the following warnings
Warning: Control Character '\i' is not valid. See 'doc sprintf' for control characters valid in the format string.
Instead, build the filename separately from the path, and then use fullfile to build the full file name (with path) as
pathName = 'F:\b';
for k=1:4
b = zeros(32,32);
fileName = fullfile(pathName,sprintf('i%d.bmp',k));
imwrite(b,fileName);
end
Your file names will look something like
F:\b\i1.bmp
F:\b\i2.bmp
F:\b\i3.bmp
F:\b\i4.bmp
Note that I replaced your index of i with k since i (and j) are also used by MATLAB to represent the imaginary number. I also removed the bmp input argument to imwrite since the image file extension has already been specified in the file name.
  댓글 수: 2
nadia
nadia 2014년 11월 8일
thank you very much for your helps
Image Analyst
Image Analyst 2014년 11월 8일
Or you can just use forward slashes. Windows understands forward slashes just fine - no need to use backslashes.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by