0

I have 3 sets of 30 data points X,Y,Z. I would like to make the 4th dimension color. However the 4th dimension I want to use is a different length than my X,Y,Z (133 vs 30).

This is a problem when using the scatter3 function in MATLAB, as the color dimension must match the size of X,Y,Z.

I also want to animate this plot in .avi format, and have the 4th dimension (color) change as the movie progresses.

Thanks in advance.

WendiKidd
  • 4,333
  • 4
  • 33
  • 50
user1412994
  • 35
  • 1
  • 2
  • 9
  • Why is it a different length? How does your colour vector match with the elements of your XYZ vectors? If it links via physical dimensions (rather than say pixels) then you can probably solve this by either interpolating your XYZ data or down-sampling your colour data. – Dan Jul 12 '12 at 15:09
  • Does each point need its own color, or do you want all the points to be the same color, with that color changing over time? – tmpearce Jul 12 '12 at 15:17
  • Each point can be the same color to start out, but I may want to change it so that each point can follow a different color pattern. – user1412994 Jul 12 '12 at 15:28
  • Hey Dan I can't reply directly to your comment for some reason - The color is a different length because it represents a quantity that changes with time. This is experimental data. The X,Y,Z are fixed components, and the 4th dimension is my measurement (voltage) that changes with time. – user1412994 Jul 12 '12 at 15:29

1 Answers1

1

Create a 2D or 3D matrix to define your colors: 2D if you use colors indexed into the colormap, or 3D if you want to give RGB values.

X=1:30;Y=randperm(30);Z=ones(size(X));
voltage_matrix = ...; %# 30 by 133 
cdata = voltage_matrix;
handle = scatter3(X,Y,Z);

colormap('jet')
set(gca,'clim',[min(voltage_matrix) max(voltage_matrix)])

for t=1:size(cdata,2) %# 1 to 133
    set(handle, 'cdata', cdata(:,t));
    pause(.1)
end

Edit: note the colormap and axes 'clim' property.

tmpearce
  • 12,523
  • 4
  • 42
  • 60
  • The above code just changed all my points to a light green color. I would like to have them change color as it progresses through the 4th dimension. The 4th dimension is a voltage I recorded with a DAQ. So it changes from data point 1 to 133, I would like the animation to show that if possible. Thanks – user1412994 Jul 12 '12 at 19:12
  • See edit. This example will generate changing colors over time. – tmpearce Jul 12 '12 at 19:22
  • This is absolutely amazing!! The only thing I need to do now is make a legend to go with the colors. That is a really incredible visualization tool! – user1412994 Jul 12 '12 at 20:36
  • Do you have an idea of how to create such legend? – user1412994 Jul 12 '12 at 20:51
  • Take a look at `colorbar` for starters. And you can choose from many predefined `colormap`s, or even create your own. Just google it or type `help colorbar` or `help colormap` in matlab. – tmpearce Jul 12 '12 at 20:53
  • colorbar does the trick. Thanks again. If I wanted to make this into a .avi movie for use in powerpoint do you know of an easy way? Right now I am thinking of just using a screen capture software. In this question a user was able to help me animate, was wondering if I could use a similar technique? http://stackoverflow.com/questions/11418385/matlab-animate-line-plots-from-data – user1412994 Jul 12 '12 at 21:02
  • Also with colorbar, it shows the scale as 1 to 133. Is it possible to map this over to time or voltage? My data acquisition rate was 40 microseconds, so could I just do data point # * data acquisition rate, to give me time on the colorbar scale? – user1412994 Jul 12 '12 at 21:03
  • Sorry to be so difficult, but also the plot is basically just changing color from points 1 to 133. I need the color to change based on the value that is length 1 to 133. For example it does not always go linearly, sometimes it (voltage) goes up and down. So I would like the color to be able to follow such a pattern. – user1412994 Jul 12 '12 at 21:09
  • It was just an example. Try and understand how it works and you'll easily be able to adapt it further. I've edited. You basically just need to take the voltage as your `cdata` instead of the time. Also, to save it, either try the method the post you linked used, or else use screen-capture software. Either way works. – tmpearce Jul 12 '12 at 21:21
  • I figured it out! Instead of using (1:133) in the 'cdata' line, I used my 1 by 133 matrix. Then I changed the 'set' line to reflect the new axis dimensions. – user1412994 Jul 12 '12 at 21:26
  • The screen capture software I am using (camtasia) keeps messing up the resolution, such that it does not capture whats happening. Would I just stick this inside of the for loop using aviobj? Not sure how that would work... – user1412994 Jul 13 '12 at 14:54
  • I use the [VideoWriter](http://www.mathworks.com/help/techdoc/ref/videowriterclass.html) class - it works very well. The online documentation describes everything you need to know to get it to work. – tmpearce Jul 13 '12 at 15:03
  • That worked perfectly! Straightforward to use, I am all set now. Thanks so much. – user1412994 Jul 13 '12 at 15:14
  • Is there a way to increase the resolution using videowriter? It is capturing my plot but chopping off the edges. – user1412994 Jul 13 '12 at 15:39
  • I see that I can change height and width in properties, but it doesn't show how to actually code that part. – user1412994 Jul 13 '12 at 15:43
  • I used: writerObj.FrameRate = 5; and that worked fine. So I tried: writerObj.Height = 600; And that did not work. Do you know the format if I want to enter the height and width? – user1412994 Jul 13 '12 at 15:51
  • `Height` is a read-only property - you can't change it, it is given by the height of the object you're capturing frames from. My guess is that you need to do `getframe(gcf)` rather than just `getframe`: without an argument, it takes just the axes. With `gcf` (or a figure handle you've saved already) it will capture the entire figure window. – tmpearce Jul 13 '12 at 15:56
  • That did the trick! You're amazing man. I will post my full code here as an answer later this afternoon so hopefully it can help others. – user1412994 Jul 13 '12 at 16:01