I am trying to create a folder of images using imwrite in a for loop. All previous problems with imwrite seem to stem from a permission problem or incorrect file naming. I have ensured my file permissions are correct in windows and I cannot find any error in my file naming. I first create a folder path using mkdir. Then, within a loop I define my image and its name, then save it using imwrite. Within imwrite I use fullfile(path,name) to create a correct file name at the location I want.
Here is my simple code
gval = 0.5;
grey = repelem(gval,95);
grey = uint8(grey*255);
wc = 608/2;
hc = 684/2;
w = 100;
h = 200;
path = fullfile(pwd,'grey_beams',['grey_shrinkage_control_' 'grey_val_' strrep(num2str(gval),'.','-')]);
for i = 1:96
I = uint8(zeros(684,608));
if i > 3 && i < 96
I(hc-h:hc+h,wc:wc+w) = 255;
I(hc-h:hc+h,wc-w:wc-1) = grey(i);
elseif i <= 3
I(hc-h:hc+h,wc-250:wc+250) = 255;
name = ['pattern_' sprintf('%03d',i-1) '.bmp']
This gives me the following error for the first iteration of the loop
This code works perfectly when I delete '.bmp' from name on line 25. But, then it saves the files with no particular format, when, instead, I need them to be a bitmap.
Furthermore, the given code will work if I insert
before the imwrite on line 26. However, then the code is slowed down significantly, and I have 96 tabs in the editor window that I have to close manually.
What is causing this file permission error?