Error in saveas, invalid or missing path

6 visualizaciones (últimos 30 días)
Vina Dewi Lestari Putra
Vina Dewi Lestari Putra el 14 de Abr. de 2021
Respondida: Rik el 14 de Abr. de 2021
Dear MATLAB users,
I am running a script to analyse 3D images and apply a loop to save the image once i finish selecting area of interest in a series of stacks. I run this on a lif. file containing the different z-stacks and the script is written to detect this dataset and specify labels too. Recently, i encounter this error:
Error using saveas (line 138)
Invalid or missing path: D:\Vina\ 1nM 45000 48 h 3D 1; plane 1/_cell1.png
Error in ReadLifStacks_SemiAutomaticSegmentCells3D_Vina (line 116)
saveas(1,[PathName char(curstackname(1:end-1)) '_cell' num2str(cell) '.png'])
What could be the reason for this?
I really appreciate if anyone can please help me troubleshoot this.
Sincerely,
Vina

Respuestas (1)

Rik
Rik el 14 de Abr. de 2021
You should create a path from parts by using fullfile. That way you avoid having to think yourself about which filesep to use.
You can use parts of my GetWriteableFolder function to test if Matlab has write (and delete) permissions for a given folder.
function tf=TestFolderWritePermission(f)
%Returns true if the folder exists and allows Matlab to write files.
%An empty input will generally test the pwd.
%
%examples:
% fn='foo.txt';if ~TestFolderWritePermission(fileparts(fn)),error('can''t write!'),end
%Test folder existence.
if ~( isempty(f) || exist(f,'dir') )
tf=false;return
end
fn='';
while isempty(fn) || exist(fn,'file')
%Generate a random file name, making sure not to overwrite an existing file.
%This will try to create a file without an extension.
[ignore,fn]=fileparts(tmpname('write_permission_test_')); %#ok<ASGLU>
fn=fullfile(f,fn);
end
try
%Test write permission.
fid=fopen(fn,'w');fprintf(fid,'test');fclose(fid);
delete(fn);
tf=true;
catch
%Attempt to clean up.
if exist(fn,'file'),try delete(fn);catch,end,end
tf=false;
end
end
function str=tmpname(StartFilenameWith)
str=tempname;[p,f]=fileparts(str);str=fullfile(p,[StartFilenameWith f]);
end

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by