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

3 vues (au cours des 30 derniers jours)
Arun Kumar Singh
Arun Kumar Singh le 26 Août 2020
Réponse apportée : Sourabh le 20 Fév 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).

Réponses (1)

Sourabh
Sourabh le 20 Fév 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:

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by