Asked by Bran
on 18 Jan 2013

So I plan to represent some data in terms of a sphere. I want to draw a sphere using my x y and z coordinates which I think I know how to do but then I would like to colour code the surface of the sphere dependent on the values of my function which depend on x and y z so to have for example, red for high values blue for low etc. any ideas how I go about this?

Many thanks guys! :)

*No products are associated with this question.*

Opportunities for recent engineering grads.

## 10 Comments

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59232#comment_123526

color code the vertices or the faces? If the vertices is color interpolation to be done along the edges or faces?

## Bran (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59232#comment_123670

Thanks for asking em to clarify Walter. Ok so I have take my coordinates and used them to draw a sphere using the following code;

What I would like to do now is colour code the surface of the sphere so the colours represent FFT values calculated at my coordinates. So I dont really kow which would be best to use, the faces or vertices.

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59232#comment_123678

Where do you want the colors to change, and should the change be abrupt or should they shade into each other?

## Bran (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59232#comment_123706

Ideally they would change and shade into eachother ... I thought perhaps to use Surf (x, y z, c) but I dont know if that would give me the coreect effect?

Also I am having trouble isolating the information on the other shell.. My function containing the FFts is called A and I want just the FFT values on the other surface, coordinates;

I let this matrix be P , but when I ask for A(P) I get the following error; Subscript indices must either be real positive integers or logicals.

So I understand I must isolate the acual indices where these points occur but how do I do this??

Many many thanks Walter in advance :)

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59232#comment_123708

FFT of what? FFT is usually by frequency (or angle), rather than spatial. Depending on what you are doing there might not

beany particular coordinates associated with the FFT. Or there might be a whole bunch of FFT coefficients associated with each coordinate.Broadly speaking, if you are not doing FFT of a spherical function (including the possibility of FFT of a series of voxels arranged as a sphere), then you would probably not expect a spherical output of the FFT.

## Bran (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59232#comment_123709

Yea I get your point thanks so much Walter for drawing that to my attention I calculated the FFT of a signal that was sampled at various cartesian coordinates... so to work out a pdf... however, I thought a sphere that was colour coded may be a good way to represent the resulting peak that was produced... I am prob approaching this in the wrong way

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59232#comment_123711

The FFT output is usually the same shape as the input (though that can vary if you use non-default number of points, or if you are doing an FFT over irregular points)

The input coordinates: are they 2D or 3D? Arranged in a circle? Arranged in a sphere? Arranged in rectangle? Regularly spaced or Irregularly spaced?

## Bran (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59232#comment_123712

The input was 3D arranged in a sphere :)

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59232#comment_123713

Ah, then spherical output representation becomes reasonable -- though surface of the sphere vs sphere as a volume becomes a consideration.

I take it you wrote your own spherical FFT routine? For any particular cubiod array input indices (I,J,K), what location is mapped to in your array that you put through your FFT routine? I presume here that the FFT routine puts its results into exactly the same logical shape as what was passed to it? If so then you should then be able to reverse the process to map the outputs back to cubiod array indices.

Notusing sphere(), just based on the exact reverse of the mapping that was used in the input processing. Once the FFT values are mapped back to cubiod array locations, we can proceed to do a voxel viewing or spherical surface generation.## Bran (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59232#comment_123773

Hi there well yea my samples were taken of coordinates that are arranged in a spherical volume. However a map of the points of the surface where the colour reflects the value of the points would be enough. Yea the FFT routine retains the shape of the input, so for example if I simply use scatter all the points can be seen. But it's difficult to see a peak in the middle thats in red amongst densely packed blue points so I was thinking to just show the peak at the surface. The suggestion is really good but how would I go about coding for this?

as I say I dont need to go back to the original locations as the output is already in the correct locations. Hence I just need to use the points at the surface to draw the sphere and then somehow use the FFT vlaues at the points to map for colour?? What do you reckon?? PS I really appreciate you taking so much time Walter!!!! :)