1
votes

I am trying to write a script to plot florescence intensity from some microscopy data as a scatter plot and threshold this data based on cells that respond greater than a certain amount in CFPMAX and plot these in green and cells that do not in red. When I try to plot this, I am unable to really assign proper colors to points and they end up being blue and red. I need each cell in the image to be assigned 4 values, (3 values for for each florescence channel and one value to determine whether or not it responded (green or red). Thus I was wondering if it was possible to assign the proper color to the 4th column of the matrix, or if I am going about this the wrong way all together. I have attached my code below.

MCHR=csvread('data1.csv');
MYFP=csvread('data2.csv');
MCFP=csvread('data3.csv');

CFPMAX=(max(MCFP))';
MCHMAX=(max(MCHR))';
YFPMAX=(max(MYFP))';

c=zeros(length(CFPMAX));

for i=1:length(c)
    if CFPMAX(i)>40
        c(i)='g'; %// green responders
    else
        c(i)='r'; %// red non-responders
    end
end

MM=horzcat(MCHMAX,YFPMAX,CFPMAX,c);


scatter(MM(:,1),MM(:,2),100,MM(:,4),'filled','MarkerEdgeColor',[0 0 0])
title('Responders vs Non-Responders ')
xlabel('[TF1]') %// x-axis label
ylabel('[TF2]') %// y-axis label
1

1 Answers

1
votes

As far as I can tell from the documentation, the input parameter c (assuming scatter(x,y,a,c,...)) can be one of:

  • A single character specifying a colour e.g. 'g' or 'r'. But just one single scalar colouring all of you points.
  • A single RGB triple colouring all of your points so [1,0,0] for red or [0,1,0] for green.
  • A three column matrix of RGB triples. This is likely what you want. I will demonstrate this to you.
  • A one column matrix of numbers which will colour the points according to a colormap. This one will also work for you but less explicitly. Incidentally, I would guess that this is option that MATLAB though your vector of characters was.

So in order to create the matrix of RGB triples you can modify your code to be

c=zeros(length(CFPMAX),3);
for i = 1:length(CFPMAX)
    if CFPMAX(i)>40
        c(i,:)=[0,1,0]; %// green responders
    else
        c(i,:)=[1,0,0]; %// red non-responders
    end
end

However, you could actually do away with the for-loop completely in MATLAB and construct c in a vectorized approach using logical indexing:

c=zeros(length(CFPMAX),3);
c(CFPMAX > 40, 2) = 1;  %// green responders
c(CFPMAX <= 40, 1) = 1; %// red responders

This is a more idiomatic way to do this in MATLAB.