Scatter matrix of probability of occurrence

14 views (last 30 days)
Hii
I have a set of data corresponding to two Variables Hs and Tp and I need to generate a scatter matrix with probablities of occurence as given in the figure below.
I was able to split Hs values into intervals using 'discretize' and seperate corrosponding Tp values using,
%% SCATTER PLOT
clc; clear all; close all;
Hs = table2array(readtable('Wave.xlsx','Range','A2:A5849'));
Tp = table2array(readtable('Wave.xlsx','Range','B2:B5849'));
edges = 0:0.5:4;
limit = length(edges)-1;
binindices = discretize(Hs,edges);
splitHs = arrayfun(@(bin) Hs(binindices == bin), 1:limit, 'UniformOutput', false);
splitTp = arrayfun(@(bin) Tp(binindices == bin), 1:limit, 'UniformOutput', false);
celldisp(splitHs);
However im having a hard time figuring out a way to build the matrix. any help would be appreciated.
Data is attached. Thank you!

Accepted Answer

Simon Chan
Simon Chan on 13 Apr 2022
You may use function hiscounts2
rawdata = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/963270/Wave%20data_Galle_NARA.xlsx');
Hs_edges = 0:0.5:6;
Tp_edges = 4:1:22;
[N,Xedges,Yedges,binX,binY] = histcounts2(rawdata(:,2),rawdata(:,1),Tp_edges,Hs_edges,'Normalization','probability');
N
N = 18×12
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0003 0.0015 0.0002 0 0 0 0 0 0 0 0 0 0.0010 0.0065 0.0032 0 0 0 0 0 0 0 0 0 0.0007 0.0044 0.0145 0.0012 0.0003 0 0 0 0 0 0 0.0014 0.0067 0.0027 0.0032 0.0014 0.0017 0.0005 0 0 0 0 0 0.0108 0.0246 0.0038 0.0012 0.0009 0.0014 0.0019 0.0002 0 0 0 0 0.0171 0.0722 0.0347 0.0043 0 0 0 0 0 0 0 0 0.0144 0.0667 0.0332 0.0245 0.0031 0.0002 0 0 0 0 0 0 0.0139 0.0846 0.0369 0.0234 0.0022 0 0 0 0 0 0 0 0.0128 0.0716 0.0438 0.0258 0.0046 0 0 0 0 0 0

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by