gscatter edit group or filter data

4 vues (au cours des 30 derniers jours)
SiTekElectroOptics
SiTekElectroOptics le 2 Juil 2019
Réponse apportée : Satwik le 16 Avr 2025
Hello,
I am using gscatter, at the moment successfully but I dont get what I want when it comes to a more selective plotting.
So far, I can plot lets say:
figure()
p = gscatter(A,B,C); % where A,B are double and C is cell
BUt now, I would like to select fewer groups to plot from C, but still without blending the order in relation to A and B.
Therefore, I get emply cells in the new C(lets call it D) but I can replace them with 'Nothing'.
The question is: When I use gscatter again
p1 = gscatter(A,B,D);
I would like either the 'Nothing' to be out of the plot OR filter C group in such a way that I dont get zeros or empty cells in between but also not loosing the order of data.
As information A(1) goes with B(1) and C(1) or D(1).
I would appreciate some help on that.
Let me know if I shuld clarify something better.

Réponses (1)

Satwik
Satwik le 16 Avr 2025
Hi,
To selectively plot specific groups using 'gscatter' without losing the order of data or plotting unwanted groups like, we can filter the data before plotting it. Here is an example code which demonstrates the above approach:
% Example data
A = rand(10, 1);
B = rand(10, 1);
C = {'Group1', 'Group2', 'Nothing', 'Group1', 'Group3', 'Nothing', 'Group2', 'Group1', 'Group3', 'Nothing'};
% Specify groups you want to plot
groupsToPlot = {'Group1', 'Group2', 'Group3'};
% Create a logical index for the groups you want to plot
isGroupToPlot = ismember(C, groupsToPlot);
% Filter A, B, and C based on the logical index
A_filtered = A(isGroupToPlot);
B_filtered = B(isGroupToPlot);
C_filtered = C(isGroupToPlot);
% Plot using gscatter
figure();
p1 = gscatter(A_filtered, B_filtered, C_filtered);
% Customize plot (optional)
xlabel('A');
ylabel('B');
title('Selective Group Plot');
legend(groupsToPlot);
Kindly, refer to the following documentation for more information on the 'ismember' function: https://www.mathworks.com/help/matlab/ref/double.ismember.html
I hope this helps!

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by