Plotting subsets of a large dataset

6 visualizaciones (últimos 30 días)
Maja Zdulska
Maja Zdulska el 20 de Oct. de 2020
Editada: Mario Malic el 20 de Oct. de 2020
Hi all,
I'm trying to create a code that would enable me to plot subsets of my data (sample attached). I want to be able to divide the datasets by time and location (so for example I can plot the data for January only at location latitude=23.1, longitude=59.2). I have a function that enables me to do it for months only:
%function that enables to plot wave data from full basin, taking into
%account only data from a chosen month
%for clarity, only one of the data variables (Mean Period) is taken into account
function plotmonth(filename, month)
%load data
data=readtable(filename);
%Extract data from a chosen month. The function Extract is included in the
%further part of the script
[year,meanper]= Extract(data,month);
%create a plot
figure(1)
clf
plot(year,meanper,'b')
xlabel('Year')
ylabel('Mean Period')
hold on
%fit a trendline through the data
meanper_coeff=polyfit(year,meanper,1);
meanper_trend=polyval(meanper_coeff,year);
plot(year,meanper_trend,'r');
hold on
%test the trend for significance
%clearing and new variables are introduced to avoid overwriting p and h
%with every function call (i.e. for each figure)
[p,h]=ranksum(year,meanper);
meanper_p=p;
meanper_h=h
clear p
clear h
%This is the Extract function, which extracts data subsets associated with
%a given month
function [year,meanper]= Extract(data,month)
switch month
case 1
Jan=(data.Month==1);
year = data.Year(Jan);
meanper = data.MeanPeriod(Jan);
case 2
Feb=(data.Month==2);
year = data.Year(Feb);
meanper = data.MeanPeriod(Feb);
end
end
However, if I were to just build up on the Extract function, the whole process would take ages (the dataset includes over 1000 different locations). Any tips on how to speed up the process? Is there another way I could do it?
Best regards,
Maja
  1 comentario
Mario Malic
Mario Malic el 20 de Oct. de 2020
Editada: Mario Malic el 20 de Oct. de 2020
I believe you might be looking for datastore function. There is a video example on it on YouTube with the title "Data Analytics with MATLAB | Master Class with Loren Shure" around 28:30.

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by