why am i getting this error ? what to do?

3 次查看(过去 30 天)
dirpath=('C:\Users\AKASH\Pictures\works\**');
files=dir('C:\Users\AKASH\Pictures\works\**\3B*');
nfiles=length(files);
datadir = 'C:\Users\AKASH\Pictures\works\**';
fname = '3B42.19980101.00.7.SUB.nc';
lat1 = ncread([datadir,fname],'latitude');
lon1 = ncread([datadir,fname],'longitude');
Error using internal.matlab.imagesci.nc/openToRead (line 1259)
Could not open C:\Users\AKASH\Pictures\works\**3B42.19980101.00.7.SUB.nc for reading.
Error in internal.matlab.imagesci.nc (line 121)
this.openToRead();
Error in ncread (line 53)
ncObj = internal.matlab.imagesci.nc(ncFile);

采纳的回答

JAYANTH BHIMAVARAPU
编辑:JAYANTH BHIMAVARAPU 2018-6-21
Replace datadir = 'C:\Users\AKASH\Pictures\works\**'; with datadir = 'C:\Users\AKASH\Pictures\works\**\'; and try again. But don't forget to change * * with exact file location path.
  2 个评论
Stephen23
Stephen23 2018-6-21
@JAYANTH BHIMAVARAPU: how will that help if that directory still does not exist, and so concatenting it (with or without the file separator) will always produce an error?
JAYANTH BHIMAVARAPU
Yeah I understood your point but I mean to say that if he gives the correct path to that .nc file with file separators, he can access that file for reading.

请先登录,再进行评论。

更多回答(1 个)

Stephen23
Stephen23 2018-6-21
编辑:Stephen23 2018-6-21
Read the error message. Is datadir = 'C:\Users\AKASH\Pictures\works\**' a directory that exists on your computer? Is C:\Users\AKASH\Pictures\works\**3B42.19980101.00.7.SUB.nc the full name of a file on your computer? Neither that path nor that file exist on your computer. You can see these names clearly in the error message and your code, so it is easy to see why there is an error.
Also, use fullfile rather than string concatenation. If you don't need to use the recursive search, then you will need to do something like this:
D = 'C:\Users\AKASH\Pictures\works';
S = dir(fullfile(D,'3B*.nc'));
for k = 1:numel(S)
fnm = fullfile(D,S(k).name);
lat = ncread(fnm,'latitude');
lon = ncread(fnm,'longitude');
...
end

类别

Help CenterFile Exchange 中查找有关 Encryption / Cryptography 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by