Use color as fourth dimension on a surf or mesh plot?
13 views (last 30 days)
Show older comments
Megan LaMonica on 11 Jan 2023
Answered: Cris LaPierre on 11 Jan 2023
I have data with four dimensions. I have plotted 3 of the 4 dimensions successfully as a mesh and surf plot. Now, I would like color to represent the fourth dimension (i.e.: not corresponding to the Z value, but separate from it).
I tried to implement color as follows:
where 'data' is my n x m x p matrix of the fourth dimension values I want plotted. However, the documentation suggests that I need an m x n or n x m x 3 matrix instead. What can I do to visualize my fourth dimension as color? Would I need to use slices, or could I somehow reshape the data to work?
Currently, I get the following error:
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in matlab.images.internal.ind2rgb (line 24)
rgb(1:height, 1:width, 1) = reshape(cm(indexedImage, 1), [height width]);
Error in ind2rgb (line 17)
r = matlab.images.internal.ind2rgb(a, cm);
Any help would be much appreciated! Thank you for your time.
Cris LaPierre on 11 Jan 2023
I'm not exactly sure what if this is the answer is helpful, as the solution may be dependent on your specfic data. Consider saving your variables to a mat file and attaching it to your post.
Here's an example that creates a surf using sin and cos, but colors it using the RGB data from peppers.png
[img,cmap] = imread('peppers.png');
[X,Y] = meshgrid(x,y);
Z = sind(X) + cosd(Y);
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!