Plot for Month and year
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ara
el 29 de Mayo de 2024
Comentada: Ara
el 29 de Mayo de 2024
Dear All,
I have data with format of NETCDF file. I can read one of them and plot it. For each day I have many data so I wish to read all of them to provide result for one day and then expand it to provide it for month and year. Also, I would like to have a data in .mat format, for example for each month. Would you please help me in this regard?
Best,
Ara
3 comentarios
Respuesta aceptada
Manikanta Aditya
el 29 de Mayo de 2024
Editada: Manikanta Aditya
el 29 de Mayo de 2024
Based on the understanding from your explaination in the question, you can use some MATLAB functions and script for it.
Use can use the 'ncread' function: https://in.mathworks.com/help/matlab/ref/ncread.html
Check it out:
% Define paths to your NETCDF files
netcdfPath = 'path/to/netcdf/files/';
% Define output directory for processed data
outputDir = 'path/to/output/directory/';
% Loop through each NETCDF file
netcdfFiles = dir(fullfile(netcdfPath, '*.nc'));
for fileIdx = 1:numel(netcdfFiles)
% Read NETCDF file
ncFile = fullfile(netcdfPath, netcdfFiles(fileIdx).name);
% Read necessary data from NETCDF file (use appropriate commands for your data)
data = ncread(ncFile, 'variable_name');
% Process daily data (e.g., calculate daily averages)
dailyAverage = mean(data, 'all');
dailyDataFileName = fullfile(outputDir, ['daily_data_', datestr(netcdfFiles(fileIdx).datenum, 'yyyymmdd'), '.mat']);
save(dailyDataFileName, 'dailyAverage');
end
% Aggregate daily data to monthly
monthlyDataFileName = fullfile(outputDir, ['monthly_data_', datestr(netcdfFiles(fileIdx).datenum, 'yyyymm'), '.mat']);
save(monthlyDataFileName, 'monthlyData');
% Aggregate monthly data to yearly
yearlyDataFileName = fullfile(outputDir, ['yearly_data_', datestr(netcdfFiles(fileIdx).datenum, 'yyyy'), '.mat']);
save(yearlyDataFileName, 'yearlyData');
- Consider this workaround script as a base and it should help you to start off.
I hope this gives you some help with your query!
7 comentarios
Manikanta Aditya
el 29 de Mayo de 2024
@Ara,
To create a contour plot of Vertical Total Electron Content (VTEC) from the daily .mat files, you'll need to follow these steps:
- Load Data from .mat Files
- Interpolate and Contour Plot
% Define the path to your .mat files
matPath = 'path/to/output/directory/';
matFiles = dir(fullfile(matPath, 'daily_data_*.mat'));
% Initialize arrays to store the combined data
allLongitudes = [];
allLatitudes = [];
allVTEC = [];
% Loop through each .mat file and load the data
for fileIdx = 1:numel(matFiles)
% Load the daily data file
matFile = fullfile(matPath, matFiles(fileIdx).name);
data = load(matFile);
% Assuming the data structure contains longitudes, latitudes, and VTEC
longitudes = data.longitudes;
latitudes = data.latitudes;
VTEC = data.VTEC;
% Append the data to the combined arrays
allLongitudes = [allLongitudes; longitudes];
allLatitudes = [allLatitudes; latitudes];
allVTEC = [allVTEC; VTEC];
end
% Ensure all three arrays have the same length
minLength = min([length(allLongitudes), length(allLatitudes), length(allVTEC)]);
allLongitudes = allLongitudes(1:minLength);
allLatitudes = allLatitudes(1:minLength);
allVTEC = allVTEC(1:minLength);
% Create a meshgrid for longitude and latitude
[lonGrid, latGrid] = meshgrid(unique(allLongitudes), unique(allLatitudes));
% Interpolate VTEC onto the grid
VTEC_grid = griddata(allLongitudes, allLatitudes, allVTEC, lonGrid, latGrid, 'natural');
% Create the contour plot
figure;
contourf(lonGrid, latGrid, VTEC_grid);
colorbar;
title('Contour Plot of VTEC');
xlabel('Longitude (degrees)');
ylabel('Latitude (degrees)');
c = colorbar;
c.Label.String = 'VTEC (TECU)';
Más respuestas (0)
Ver también
Categorías
Más información sobre NetCDF en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!