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'])
% 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.
0 个评论
回答(1 个)
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
2023-7-18
fp = 'C:\Users\Madison-Riley\Desktop\Copernicus Data';
ncdisp(fullfile(fp,'June1972.nc'))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!