legend with specific colors

3 Ansichten (letzte 30 Tage)
milad farshbaf
milad farshbaf am 6 Jan. 2019
Bearbeitet: milad farshbaf am 7 Jan. 2019
hi, how can i use legend with my specific colors and Depth in this code?
figure
for n = 1:length(Lon)
if Depth(n,1)>=0 && Depth(n,1)<=20
jj = [0 1 0];
elseif Depth(n,1)>20 && Depth(n,1)<=40
jj = [0 1 1];
elseif Depth(n,1)>40 && Depth(n,1)<=60
jj = [0 1 0];
elseif Depth(n,1)>60 && Depth(n,1)<=90
jj = [1 0 0];
elseif Depth(n,1)>90 && Depth(n,1)<=10000
jj = [0 0 0];
end
h(n) = plot(Lon(n,1),Lat(n,1),'o','MarkerFaceColor',jj,'MarkerEdgeColor','k'); hold on
legend('0-20','20-40','40-60','60-90','90-10000');
end

Akzeptierte Antwort

Shubham Gupta
Shubham Gupta am 7 Jan. 2019
Right now you are plotting one dataset of 'Lon' and 'Lat' at a time and this will give you a plot with number of datasets equal to the length of 'Lon' vector. You would like to plot all the datasets of 'Lon' and 'Lat' vectors with specific interval at once. So, you will have number of datasets according to the number of intervals you have. which will be easier to show on legend imo.
Here's one way to do it :
interval=[0,20,40,60,90,10000]; % Interval Matrix
col=hsv(length(interval)-1); % Color matrix for markers
figure
for n = 1:length(interval)-1
minI=interval(n); % max of Interval
maxI=interval(n+1); % min of Interval
Ind=find(Depth>=minI&Depth<maxI); % get indeces according to the interval
plot(Lon(Ind,1),Lat(Ind,1),'o','MarkerFaceColor',col(n,:),'MarkerEdgeColor','k');
hold on;
end
legend('0-20','20-40','40-60','60-90','90-10000');
I hope this helps.
  1 Kommentar
milad farshbaf
milad farshbaf am 7 Jan. 2019
Bearbeitet: milad farshbaf am 7 Jan. 2019
This is exactly what i want, tnx tnx :)))

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by