Modify function to take input argument of marker

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Adam Danz
Adam Danz il 14 Mag 2019
Modificato: Adam Danz il 14 Mag 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 Commenti
Meg Cullen
Meg Cullen il 15 Mag 2019
I tried out both the proposals and Proposal 1 is actually much easier. Thank you very much. :)
Adam Danz
Adam Danz il 15 Mag 2019
Good choice. The first one is definitely the way to go.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Formatting and Annotation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by