필터 지우기
필터 지우기

How do you color code scatter3 based off of a fourth variable?

조회 수: 4 (최근 30일)
Cynthia Dickerson
Cynthia Dickerson 2016년 8월 24일
답변: Steven Lord 2016년 8월 25일

I have a 128X5 matrix. I want the (:,3) (:,4) and (:,5) columns to be the x, y, and z coordinates of each point, respectively. However, I also want to color-code the points based off of the data pairs located in (:,1) and (:,2).

So, for example:

[0,1,x,y,z;2,0,x,y,z;0,-1,x,y,z;...0,1,x,y,z;2,0,x,y,z;0,-1,x,y,z]

And I would want any data with the (0,1) or (0,-1) pairs in the first two columns to show up red, (2,0) and (-2,0) to show up blue, and 2 other coordinate pairs to be graphed in black. The number appearing in column 1 is distinct, so I probably don't need to consider the coordinate pair, just the column 1 value.

How can I do this?

Currently, my code looks like this:

      if v == dimension
      %Make a matrix to hold all of the RSD_c{}
      RSD_compiled=zeros(1,5);
      for t=1:v
          RSD_compiled=[RSD_compiled;RSD_c{1,t}];
      end
      %Remove first line of zeros used to initialize matrix
      RSD_compiled=RSD_compiled(2:end,:)
   % Data needs to be color-coordinated.       
  figure('name', 'RSD vs. B vs. v');
  scatter3( RSD_compiled(:,3), RSD_compiled(:,4), RSD_compiled(:,5) );
  title(['Relationship Between Relative Standard Deviation, Bootstrap Replicates, and Dimension for radfrac =', num2str(radfrac), 'and TN =', num2str(u*50)]);
  xlabel('Bootstrap Replicates'); % x-axis label
  ylabel('Relative Standard Deviation'); % y-axis label
  zlabel('Dimensions'); % z-axis label
  end

채택된 답변

Steven Lord
Steven Lord 2016년 8월 25일
Use a vector of length equal to the number of points as the fifth input argument to scatter3. If you don't want to vary the size of the markers, specify the fourth input argument as [] to use the default.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by