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

10 次查看(过去 30 天)
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 中查找有关 File Operations 的更多信息

标签

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by