Borrar filtros
Borrar filtros

Trouble running this script on windows, could you please tell me what i am doing wrong?

4 visualizaciones (últimos 30 días)
the following script runs on my Mac without any problems, but when I try to run the same script on windows (I have made sure the path name and the backslash have been used correctly) it gives me the following error:
the code i am using is:
nfiles = input('Number of tissue files available: ');
for j = 1:nfiles
DataC = dlmread(sprintf('/Users/srikantasharma/Desktop/Sept-scan/Male/106904(40db)/position-%d.txt',j)); *the code for mac*
the code for windows:
nfiles = input('Number of tissue files available: ');
for j = 1:nfiles
DataC = dlmread(sprintf('D:\srikantasharma\Desktop\Sept-scan\Male\106904(40db)\position-%d.txt',j));
Error: The file D:cannot open file because: Existenece?memory? permissions?...
When I run an individual file though it seems to run! Could you please tell me what I am doing wrong?
Many thanks.
  3 comentarios
Srikanta Sharma
Srikanta Sharma el 17 de En. de 2013
Hello Jan, the complete error message is: The file 'D:' could not be opened because: Cannot open file. Existence? Permissions? Memory? . . .
Error in ==> automated_image at 8 DataC = dlmread(sprintf('D:\Dec-30Days-2013\30-days-SI\128765(40 db)\position-%d.txt',j));
Jan
Jan el 18 de En. de 2013
SPRINTF cannot run correctly, when the format strings contains backslashes "\", because they are interpreted as escape characters. I have posted a working solution already: Use FULLFILE to join path and filename, and SPRINTF for the file name only.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 17 de En. de 2013
Change the backslashes to forward slashes. Forward slashes are acceptable to MS Windows.
The problem you have is that you have backslash sequences such as \D inside the format string for sprintf. backslashes are special in formats. For example, \t means tab and \r means carriage return.
If you prefer to write the names in terms of backslashes then recode as
DataC = dlmread(sprintf('%s%d%s','D:\srikantasharma\Desktop\Sept-scan\Male\106904(40db)\position-', j, '.txt'));

Más respuestas (1)

Jan
Jan el 17 de En. de 2013
Editada: Jan el 17 de En. de 2013
The error message is clear: Please check if the file exists:
if isunix
base = '\';
else
base = 'D:\';
end
folder = fullfile(base, 'srikantasharma\Desktop\Sept-scan\Male\106904(40db)');
for j = 1:nfiles
File = fullfile(folder, sprintf('position-%d.txt',j));
try
dataC = dlmread(File);
catch
if exist(File, 'file') ~= 2
error('Missing file: %s', File);
else
error('Cannot read existinmg file: %s', File);
end
end
end

Categorías

Más información sobre MATLAB Compiler 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