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

10 vues (au cours des 30 derniers jours)
Madison
Madison le 18 Juil 2023
Commenté : Madison le 19 Juil 2023
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.

Réponses (1)

Walter Roberson
Walter Roberson le 18 Juil 2023
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 commentaires
Stephen23
Stephen23 le 18 Juil 2023
fp = 'C:\Users\Madison-Riley\Desktop\Copernicus Data';
ncdisp(fullfile(fp,'June1972.nc'))
Madison
Madison le 19 Juil 2023
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);

Connectez-vous pour commenter.

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by