Modify function to take input argument of marker
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
In this data cluster function the plot marker by default is '.'
I want to add a input argument to the function that will let me set the marker manually for separate inputs.
The modified function will be of the form
function []=PlotClusters(Data,IDX,Centers,point_marker,Colors)
Can someone please tell how to do this?
0 commentaires
Réponse acceptée
Adam Danz
le 14 Mai 2019
Modifié(e) : Adam Danz
le 14 Mai 2019
I don't recommend editing the source code because 1) you'll have to repeate those edits every time the file is updated and 2) it's a lot more work than the first proposal below.
Proposal 1: change the marker type after plotting
Instead, just identify all of the points marked by '.' and replace the marker type.
PlotClusters(Data,IDX,Centers,Colors); % run the code
axh = gca; % get the axis handle
h = findobj(axh, 'Marker', '.'); % find all objects that have marker '.'
set(h, 'Marker', 'x') % change the marker type
Proposal 2: change the function
If you must edit the source code to specify the marker type, you'll need to make these changes:
% 1) Replace the first line
% function []=PlotClusters(Data,IDX,Centers,Colors)
function []=PlotClusters(Data,IDX,Centers,Colors,Marker)
%2) Replace this line
% plot(Data(IDX == i,1),Data(IDX == i,2),'.','Color',Colors(i,:))
plot(Data(IDX == i,1),Data(IDX == i,2),Marker,'Color',Colors(i,:))
%3) Replace this line
% plot3(Data(IDX == i,1),Data(IDX == i,2),Data(IDX == i,3),'.','Color',Colors(i,:))
plot3(Data(IDX == i,1),Data(IDX == i,2),Data(IDX == i,3),Marker,'Color',Colors(i,:))
%4) Replace this line
% case 4 %All data is given just need to check consistency
case {4,5} %All data is given just need to check consistency
%5 After the switch add these lines
if nargin < 5 || isempty(Marker)
Marker = '.';
end
* Not tested!
** I recommend the first proposal!
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Annotations 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!