Scatterplot with condition on another matrix

Hi I have 2 matrices A and B that are 1x98 that I want to plot using scatterplot. I also have the third matrix C that is used to separate the data.
So if A<=C, the dots should appear blue, and if A>C, the dots should appear black.
How do I set that up, and what the code should look like?
Thanks. I need this as soon as possible.

6 comentarios

Fabio Freschi
Fabio Freschi el 9 de Sept. de 2019
Can you share the data in a mat file?
Here it is. My code right now is
figure
for i=1:length(index_of_max_data)
if index_of_max_data>S_G2_transition_point_data;
scatter (index_of_max_data,BP1_at_max_data,'filled','r'); hold on
else
scatter (index_of_max_data,BP1_at_max_data,'filled','k'); hold on
end
end
but it does not seem like it separates the 2 conditiosn
dpb
dpb el 9 de Sept. de 2019
Editada: dpb el 10 de Sept. de 2019
That doesn't match up with anything you've written previously...there's no A,B, nor C array in that .mat file; only a cell array with a bunch of cellstr in first four columns and two numeric columns as the last two; the latter of which is replete with many NaN.
Nor are any of the variables in the above snippet defined by load 'ing the attached .mat file.
Chi Pham
Chi Pham el 10 de Sept. de 2019
I am sorry about that but A,B,C are just example names. Please see the data mat file. A is index_of_max_data, B is BP1_at_max_data and C is S_G2_transition_point_data.
I really appreciate your help
dpb
dpb el 10 de Sept. de 2019
Well, we only know what you tell us...we don't know the magic correlations. :)
See updated Answer...
dpb
dpb el 10 de Sept. de 2019
"but it does not seem like it separates the 2 conditions"
Because the syntax is incorrect for the if test. You've written the two variables w/o the subscript which returns a logical vector of the same size as they. if is true iff all elements of the condition are true; see the documenation for IF for details.
Also, even with that corrected, you've done the same thing in the argument to scatter; each time you call it, it will do the full vectors with the particular color...excepting since only the false case will ever actually execute, your code draws the same scatter plot over and over length(index_of_max_data) times, always with the same result.
See the previous Answer for "the MATLAB way"

Iniciar sesión para comentar.

 Respuesta aceptada

dpb
dpb el 9 de Sept. de 2019
Editada: dpb el 10 de Sept. de 2019
clr=[0 0 1; 0 0 0]; % blue, black RGB triplets
c=clr((A>C)+1,:); % set which based on lookup
scatter(A,B,[],c,'filled')
W/ revised .mat file and clarification of "who's who in the zoo", then the above does what Q? asks with
A=index_of_max_data.'; B=BP1_at_max_data.';C=S_G2_transition_point_data.';
If you instead want red instead of blue, fix up the clr rgb triplet to match desired color(s).

2 comentarios

figure
clr=[0 0 1 ; 0 0 0]; % blue, black RGB triplets
c=clr((index_of_CDK2drop_escape<=S_end_escape)+1,:); % set which based on lookup
scatter(index_of_CDK2drop_escape*10/60,BP1_at_CDK2drop_escape,[],c)
legend('CDK2 drop before S/G2 transition', 'CDK2 drop before S/G2 transition');
xlabel('Absolute time (hr)')
ylabel('BP1 cumsum at CDK2 drop')
Thank you for your help. I have an additional quick question though. Why does my legend only have one type of data point? It reports that Ignoring extra legend entries.
dpb
dpb el 10 de Sept. de 2019
Editada: dpb el 11 de Sept. de 2019
Ah! You didn't specify two legends! :)
"Why?" is because drawn this way you have only a single scatter() object set of points and legend() is hooked intimately with the number of objects drawn onto the axes. Only one and it'll only add one.
Two ways to fix -- first would be to select the two sections of the data and scatter() them separately instead of together. That takes extra logic to build the selection and two calls to scatter() initially.
The other is to create a set of dummy scatter() objects to label from the colors array as
...
hold on
hS=arrayfun(@(i) scatter(nan,nan,[],clr(i,:),'filled'),1:size(clr,1));
hL=legend(hS,'A','B','Location','northwest');
The above after you've done the previous plotting adds two scatter() objects that are invisible but match the two (or howerver many you define) colors and marker type as targets for the subsequent call to legend that uses those two object handles.
Your choice as to which way to do it...

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 9 de Sept. de 2019

Editada:

dpb
el 11 de Sept. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by