필터 지우기
필터 지우기

Open a file error, even though path is valid and correct

조회 수: 8 (최근 30일)
Madison
Madison 2023년 7월 18일
댓글: Madison 2023년 7월 19일
I am new to Matlab and had help writing my code, but even though the path is correct I cant get my file to open.
close all, clear all clc
% note I've renamed the files, call them what you like but they need to
% have the year in them to load in a loop
dir=('"C:\Users\Madison-Riley\Desktop\Copernicus Data"');
%look at one file to interrogate and understand dimensions and variables
ncdisp([dir,'June1972.nc'])
Error using internal.matlab.imagesci.nc/openToRead
Could not open "C:\Users\Madison-Riley\Desktop\Copernicus Data"June1972.nc for reading.

Error in internal.matlab.imagesci.nc (line 124)
this.openToRead();

Error in ncdisp (line 71)
ncObj = internal.matlab.imagesci.nc(ncFile);
% test=ncread([filepath,'June2021.nc'],'uo'); whos test
% check all your files, June2019 only had one timestep so I couldn't work with that??
% same for June2020
time=ncread([filepath,'June2022.nc'],'time'); whos time
ntime=length(time);
% get coordinate data, assuming it's the same between all files
lon=ncread([filepath,'June2021.nc'],'longitude');
lat=ncread([filepath,'June2021.nc'],'latitude');
[LON,LAT]=meshgrid(lon,lat);
I don't understnad the issue. My file is coming from the exact directory and that is teh fil;e name. I am trying to create a mean across 50 years for June (1972-2022). June 1972 was sued to understand my dimensins and variables. June 2021 was used to recieve coordinate data.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 7월 18일
Do not use the "" in the directory name.
dir = 'C:\Users\Madison-Riley\Desktop\Copernicus Data';
Do not put filenames together using [], use fullfile() instead
time = ncread(fullfile(filepath,'June2022.nc'),'time'); whos time
  댓글 수: 4
Stephen23
Stephen23 2023년 7월 18일
fp = 'C:\Users\Madison-Riley\Desktop\Copernicus Data';
ncdisp(fullfile(fp,'June1972.nc'))
Madison
Madison 2023년 7월 19일
Unforunatly, I still recieve the same error,just with fullfile.
close all, clear all clc
% note I've renamed the files, call them what you like but they need to
% have the year in them to load in a loop
fp = 'C:\Users\Madison-Riley\Desktop\Copernicus Data';
ncdisp(fullfile(fp,'June1972.nc'))
Error using internal.matlab.imagesci.nc/openToRead
Could not open C:\Users\Madison-Riley\Desktop\Copernicus Data/June1972.nc for reading.

Error in internal.matlab.imagesci.nc (line 124)
this.openToRead();

Error in ncdisp (line 71)
ncObj = internal.matlab.imagesci.nc(ncFile);
%look at one file to interrogate and understand dimensions and variables
% test=ncread([filepath,'June2021.nc'],'uo'); whos test
% check all your files, June2019 only had one timestep so I couldn't work with that??
% same for June2020
time = ncread(fullfile(fp,'June2022.nc'),'time'); whos time
ntime=length(time);
% get coordinate data, assuming it's the same between all files
lon=ncread([fp,'June2021.nc'],'longitude');
lat=ncread([fp,'June2021.nc'],'latitude');
[LON,LAT]=meshgrid(lon,lat);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by