Trouble running this script on windows, could you please tell me what i am doing wrong?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Jan
2013년 1월 18일
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.
채택된 답변
Walter Roberson
2013년 1월 17일
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'));
추가 답변 (1개)
Jan
2013년 1월 17일
편집: Jan
2013년 1월 17일
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!