How to get distinct markers for scatter plot while reading data from excel?

2 views (last 30 days)
So, I'm reading certain data from excel and I need to give each group of data that is being read with a different marker... how do I do that? Kindly help.
As of now I'm doing this:
journeys = readtable('plot1.xlsx'); /
%selecting data--------------------
[journeys.x, journeys.y] = mfwdtran(mstruct, journeys.latitude, journeys.longitude); %transform the flights latitude and longitude
in = inpolygon(journeys.x, journeys.y, X, Y);
[groupid, flights] = findgroups(journeys.flight); %assign unique id to each flight and apply to rows of the table
isallin = splitapply(@all, in, groupid); %are ALL points of the flight in the polygon? logical output
selectedflights = flights(isallin); %list of flights where all points are in the polygon
selectedjourneys = journeys(ismember(journeys.flight, selectedflights), :); %portion of the table with only the selected data
%selecting data--------------
%lets try plotting-----
[sx, sy] = mfwdtran(mstruct, selectedjourneys.latitude, selectedjourneys.longitude);
color = selectedjourneys.flight;
scatter(sx,sy,[],color, 'Marker','+') %plotting all flights in between the ats route
Here all the data have one marker '+'
But I want to give distinct markers to each group based on the group id (as mentioned above)

Accepted Answer

KSSV
KSSV on 18 Apr 2019
x = rand(100,1) ; y = rand(100,1) ;
G = 4 ; % four groups
idx = kmeans([x y],4) ;
figure
hold on
M ={'+','*','s','v'} ;
for i = 1:4
scatter(x(idx==i),y(idx==i),'Marker',M{i})
end

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!