scatter function for plotting points with different colors

txt1=[{'X1'};{'A100'};{'B100'};{'C100'};{'X2'}];
y=[100;150;200;135;140];
x=[200;250;300;225;235];
figure(1),scatter(y, x, 'b^');grid off;
text(y, x, txt1);
title('points')
xlabel('Y');
ylabel('X');
line(y,x,'Color','k','LineWidth',1);
%I need to make X1 and X2 red while the other points are black. If
txt1=[{'A100'};{'B100'};{'C100'};{'X1'};{'X2'}];
%I applied below codes to make red X1 and X2
figure(1),scatter(y, x, 36, [zeros(numel(y)-2,3);1 0 0;1 0 0], '^');grid off;
text(y, x, txt1);
title('points')
xlabel('Y');
ylabel('X');
line(y,x,'Color','k','LineWidth',1);
%How can I implement the last codes for the first situation?

4 Kommentare

However, I have no idea what's the question now? What do you need to implement? Just define txt1, y, and x and run the code I submitted before.
In my previous question, txt1 was=[{'A100'};{'B100'};{'C100'};{'X1'};{'X2'}]; now txt1 is =[{'X1'};{'A100'};{'B100'};{'C100'};{'X2'}]; thus the codes you sent me make C100 and X2 red but I need X1 and X2 to be red.
In this case
[zeros(numel(y)-2,3);1 0 0;1 0 0]
becomes
[1 0 0;zeros(numel(y)-2,3);1 0 0]
If you want to modify code you don't understand, it's better to ask for details in the respective thread instead of starting off with new questions which are almost identical.
alright, thank you for your response. I just couldn't reply in previous thread because significant time has passed thus I thought you wouldn't see my response.

Antworten (0)

Diese Frage ist geschlossen.

Gefragt:

am 19 Feb. 2015

Geschlossen:

am 20 Aug. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by