Color input to comm.Const​ellationDi​agram object

I want to display the scatterplots of 2 different users in my simulation in real-time, for which I am using the comm.ConstellationDiagram object. I would like to use different colours for each user's scatterplot to distinguish between them. However, comm.ConstellationDiagram does not take a color input.
Scatterplot function takes a color input, but I don't want the plots on different figures each time I call it. I want the points plotted in real-time in the same figure (for each user), this is why I am using the comm.ConstellationDiagram object.
Here's a snippet of how I am using it:
constDiag1 = comm.ConstellationDiagram(2, ...
"ChannelNames",{'Header','Data'}, ...
"ReferenceConstellation",{refConstHeader,refConstData1}, ...
"ShowLegend",true, ...
"EnableMeasurements",true,...
"Title",'User 1 constellation');
constDiag2 = comm.ConstellationDiagram(2, ...
"ChannelNames",{'Header','Data'}, ...
"ReferenceConstellation",{refConstHeader,refConstData2}, ...
"ShowLegend",true, ...
"EnableMeasurements",true,...
"Title",'User 2 constellation');
for frame=1:framenum
[rxHeader1,rxData1,rxHeader2,rxData2] = myfunction(captureData);
constDiag1(complex(rxHeader1(:)), ...
complex(rxData1(:)));
constDiag2(complex(rxHeader2(:)), ...
complex(rxData2(:)));
end
Is there a way to include a colour input to the configuration of the object?
If not, how can I go about making a custom function for obtaining scatterplots in real-time (similar to what comm.ConstellationDiagram does) where I can configure each object in a different color?
Thanks! Any help is appreciated!

 Accepted Answer

You can use a single scatter() call, and record the graphics object that results. Then on subsequent loop iterations
newX = [SCATTEROBJECT.XData; real(rxHeader1(:)); real(rxData1(:)); real(rxHeader2(:)); real(rxData2(:))];
newY = [SCATTEROBJECT.YData; imag(rxHeader1(:)); imag(rxData1(:)); imag(rxHeader2(:)); imag(rxData2(:))];
newC = [SCATTEROBJECT.CData; repelem('b', numel(rxHeader1)+numel(rxData1)); repelem('r', numel(rxHeader2)+numel(rxData2))];
set(SCATTEROBJECT, 'XData', newX, 'YData', newY, 'CData', newC);

1 Comment

Thanks for answering! I adapted your idea for my solution.
Maybe I wasn't clear in my question: I wanted 2 different figures with scatterplots, one for each user, to compare them side-by-side. And then in each loop iteration, I wanted the figure corresponding to each user to be updated.
This is how I adapted your code:
for frame=1:framenum
[rxData1,rxData2] = myfunction(captureData);
if ~(exist(scatter1))
figure
scatter1 = scatter(real(rxData1),imag(rxData1),'b');
title('User 1')
drawnow
figure
scatter2 = scatter(real(rxData2),imag(rxData2),'r');
title('User 2')
drawnow
else
set(scatter1,'XData',real(rxData1),'YData',imag(rxData1),'CData',repmat(scatter1.CData(1,:),size(rxData1)));
drawnow
set(scatter2,'XData',real(rxData2),'YData',imag(rxData2),'CData',repmat(scatter2.CData(1,:),size(rxData2)));
drawnow
end
end
Without the drawnow, the figures are displayed only at the end of the loop, which isn't the live plotting I needed. I hope this helps the next person.
Thank you very much for the help!

Sign in to comment.

More Answers (0)

Products

Release

R2024a

Community Treasure Hunt

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

Start Hunting!