How do you plot a wave rose/polarhistogram?

57 views (last 30 days)
Whale_Shark
Whale_Shark on 28 Nov 2022
Commented: William Rose on 29 Nov 2022
So I am relatively new to matlab and am still trying to figure out how it works. What I am trying to do currently is see if I can use (ocean) wave data to plot a windrose/waverose diagram showing annual wave direction (Direction (deg)) and wave power (P (kW/m2)). I am using a FOR LOOP to produce figures and graphs for 5 years, with each year being a separate data file. I have tried to look into using the functions rose and polarhistogram but I am struggling to understand how to input the data in the commands when looking at doc polarhistogram for example. I have attached one of the data files to this question and have input my current code below.
close all
clear all
clc
%Load in the data
fpath=uigetdir;
files=dir([fpath '\*.csv']);
files=char(files.name);
%for loop to go through the variable files, creating variables for wave
%height (Hmax [H])), wave power (P kW/m2), max period (Tmax [T]), and geographical direction in
%degrees (Directiondeg [direction]). Using textscan function to read the
%data files.
for n=1:size(files,1)
fid=fopen([fpath '\' files(n,:)]);
data{n}=textscan(fid, ['%s' repmat('%f', 1,34)],'Delimiter',',','CollectOutput',1, 'Headerlines',1);
fclose(fid);
%readtable to set datetime array for first column in the data.
T1=readtable([fpath '\' files(n,:)], 'VariableNamingRule','preserve');
VN=T1.Properties.VariableNames;
DT=T1.('Date/Time (GMT)');
T1.('Date/Time (GMT)').TimeZone='UTC';
T1.('Date/Time (GMT)').TimeZone;
%Identify and generate wave parameter variables suitable to portray the wave climate of the
%chosen sites. This identifies wave height (H), wave period (T), wave
%direction (direction), wave power (power), and time (time).
H=T1.("Hmax (m)");
T=T1.("Tmax (s)");
direction=T1.("Direction (deg)");
time=T1.("Date/Time (GMT)");
power=T1.("P (kW/m2");
%Identify and replace anomalous data with NaN.
bad=9999;
ind=find(H==bad);
H(ind)=NaN;
T(ind)=NaN;
direction(ind)=NaN;
%Plot the figures. This plots wave height against time.
figure(n);
plot(time,H,'b','LineWidth',1)
xlabel('Time','FontSize',12)
ylabel('Wave Height (m)','FontSize',12)
title(['n=' num2str(n) ' ' files(n,:)],'FontSize',12)
%Plot wave rose diagram with wave power (power) and wave direction
%(direction).
end

Answers (1)

William Rose
William Rose on 29 Nov 2022
Here is a script that plots a regular histogram of wind direction and the same data in polar form. Data is from NOAA Buoy SJSN4, quality controlled, Sept 2022. This buoy does not have wave data but it does have wind speed and direction , so that is what I used. There were 7066 valid data points in the month, out of 7200 possible (every 6 minutes).
The script makes a histogram of the good data (i.e. data for which WDIR is not 999). The top and bottom panels of the figure below are the same data, in two formats. Wind speed is not taken into account in this plot - only direction matters.
Good luck wiht your work.
  2 Comments
William Rose
William Rose on 29 Nov 2022
@Whale_Shark,The attached code works on the data file you supplied, from the data buoy at Goodwin Sands.

Sign in to comment.

Categories

Find more on Weather and Atmospheric Science in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by