I am trying to write an image that I do operations on to a ‘.tif’ file in a directory. I make the results directory with Matlab using the mkdir() function.
Here is the command I am using:
[pathstr, nameWOext, ext] = fileparts(filename);
results_dir = ['results' '/results_' nameWOext];
%check to see if the directory exists already, if it doesn't make it
if(exist(results_dir) ~= 7)
mkdir(results_dir);
end
filenamezero = [nameWOext '_J' ext];
imwrite (~J, fullfile(results_dir, filenamezero)); //Error here
When Matlab gets to this line it outputs an error:
Could not open file for writing. Check directory or file permissions.
I inspected the folder ‘results/results_’ and the folder is read-only. Apparently mkdir() is doing this automatically.
Is there anyway to get around this?
Thanks
P.S. I am running Windows 7 using Matlab 6.1
I think your problem may be your use of the
fullfilefunction. I think the result is that the path you are trying to pass toimwritehas a mix of\and/for file separators.Try using this instead: