Plotting subsets of a large dataset

12 views (last 30 days)
Maja Zdulska
Maja Zdulska on 20 Oct 2020
Edited: Mario Malic on 20 Oct 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
%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
ylabel('Mean Period')
hold on
%fit a trendline through the data
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)
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
year = data.Year(Jan);
meanper = data.MeanPeriod(Jan);
case 2
year = data.Year(Feb);
meanper = data.MeanPeriod(Feb);
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,
  1 Comment
Mario Malic
Mario Malic on 20 Oct 2020
Edited: Mario Malic on 20 Oct 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.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by