why am i getting this error ? what to do?

3 ビュー (過去 30 日間)
OMKAR ACHARJEE
OMKAR ACHARJEE 2018 年 6 月 21 日
編集済み: JAYANTH BHIMAVARAPU 2018 年 6 月 21 日
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 日
編集済み: 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
JAYANTH BHIMAVARAPU 2018 年 6 月 21 日
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 Center および File ExchangeEncryption / Cryptography についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by