How to make co-occurence Matrix Like this (as shown in Image)

1 Ansicht (letzte 30 Tage)
Arun Kumar Singh
Arun Kumar Singh am 26 Aug. 2020
Beantwortet: Sourabh am 20 Feb. 2025
I have data points for one parameter A (200 to 800) at every 5 unit resolution and another paramemter B (40 to 200) at every 1 km resolution. I would like to know how to make normalized Co occurence matrix like in the image (attached).

Antworten (1)

Sourabh
Sourabh am 20 Feb. 2025
I will help you on making a dummy normalised co-occurrence matrix as per the image by breaking it down into 2 steps – Computing the co-occurrence matrix followed by visualizing it as a heatmap.
1. Computing the co-occurrence matrix
  • Define bins for parameters A and B:
A_bins = 200:5:800; % A ranges from 200 to 800 at a 5-unit resolution
B_bins = 40:1:200; % B ranges from 40 to 200 at a 1-km resolution
  • Loading data: If you have real data, load it from a file (csv, mat, etc.). Assuming you have loaded the data for the 2 parameters in A_data and B_data
  • Make Co-occurance matrix using histcounts2” function
occurrence_matrix = histcounts2(A_data, B_data, A_bins, B_bins);
  • Normalize to range [0, 1]
normalized_matrix = occurrence_matrix / max(occurrence_matrix(:));
2. Visualizing the co-occurrence matrix as a heatmap
MATLAB provides multiple functions to plot heatmaps. Kindly follow any one the method mentioned below:
  • Using “imagesc
figure;
imagesc(A_bins, B_bins, normalized_matrix');
colormap(jet);
colorbar;
caxis([0 1]);
  • Using “pcolor
figure;
pcolor(A_bins(1:end-1), B_bins(1:end-1), normalized_matrix');
colormap(jet);
colorbar;
caxis([0 1]);
  • Using “contourf
figure;
contourf(A_bins(1:end-1), B_bins(1:end-1), normalized_matrix', 20); % 20 contour levels
colormap(jet);
colorbar;
caxis([0 1]);
Then proceed with labelling the axes accordingly.
For more information on “histcounts2”, Kindly follow the MATLAB documentation:
For more information on displaying heatmaps, kindly refer the following MATLAB documentations:

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by