Clear Filters
Clear Filters

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

8 views (last 30 days)
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.

Answers (1)

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

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!