How to create a polar histogram in Matlab using a text file

5 views (last 30 days)
i am trying to make a polar histogram showing significant wave height and wave direction in matlab but i cant figure out how to do it. any tips?

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 15 Dec 2024
% Load the data with import options
filename = 'Mlf_waves2014.txt';
opts = detectImportOptions(filename, 'FileType', 'text', 'Delimiter', '\t');
opts.VariableNamesLine = 1; % Ensure variable names are taken from the first row
data = readtable(filename, opts);
% Rename variables for easier access
data.Properties.VariableNames = {'DateTime', 'Latitude', 'Longitude', 'Flag', ...
'Hs', 'Hmax', 'Tp', 'Tz', 'Dirp', 'Spread', 'SST'};
% Extract significant wave height and wave direction
Hs = data.Hs;
Dirp = data.Dirp;
% Remove invalid data
validData = Hs < 9999 & Dirp < 9999;
Hs = Hs(validData);
Dirp = Dirp(validData);
% Convert wave direction to radians
Dirp_rad = deg2rad(Dirp);
% Create the polar histogram
figure;
polarhistogram(Dirp_rad, 16, 'Normalization', 'probability');
hold on;
% Overlay wave heights using polarscatter
polarscatter(Dirp_rad, Hs, 30, Hs, 'filled'); % Size of dots is proportional to Hs
colorbar;
colormap('jet');
title('Polar Histogram of Significant Wave Height and Wave Direction');

More Answers (0)

Categories

Find more on Polar Plots 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!