How to plot multi array in one segmentation?

2 vues (au cours des 30 derniers jours)
Mingde
Mingde le 13 Juil 2022
Réponse apportée : Satyam le 22 Avr 2025
Hello all,
I would like to plot multi array in one graph by using cx cy for plot.
this is my code and dataset.
T = readmatrix('dataset.csv')
R = reshape(
T.',size(T,2), 16, [])
size(R)
P = permute(R,[2 1 3])
size(P)
F = P(:,:,1:1622)
szf= size(F);
Ft = sum(sum(F,1),2)
cy = sum((1:szf(1)).'.*sum(F,2))./Ft
cx = sum((1:szf(2)).*sum(F,1))./Ft
imshow(F,[]); hold on
plot(cx,cy,'*','markersize',20)
the result that I want it like this.

Réponses (1)

Satyam
Satyam le 22 Avr 2025
Hi Mingde,
According to my understanding, the goal is to plot a multidimensional array in a 16 by 10 figure, where squares represent the force and crosses indicate the center of force. The squeeze function is utilized to convert cx and cy into vectors suitable for plotting. Additionally, the mean of F is computed across the third dimension for use with the imshow function.
Here is the code implementing the above functionality
T.',size(T,2), 16, []);
size(R);
P = permute(R,[2 1 3]);
size(P);
F = P(:,:,1:1622);
szf= size(F);
Ft = sum(sum(F,1),2);
cy = sum((1:szf(1)).'.*sum(F,2))./Ft;
cx = sum((1:szf(2)).*sum(F,1))./Ft;
cx=squeeze(cx);
cy=squeeze(cy);
meanF = mean(F, 3); % Take mean across the third dimension
imshow(meanF, []); % Display the mean image
hold on
plot(cx,cy,'*','markersize',10);
This approach should help achieve the desired visualization.

Community Treasure Hunt

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

Start Hunting!

Translated by