Use color as fourth dimension on a surf or mesh plot?

10 Ansichten (letzte 30 Tage)
Megan LaMonica
Megan LaMonica am 11 Jan. 2023
Beantwortet: Cris LaPierre am 11 Jan. 2023
Hello,
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:
surf(X,Y,vq,ind2rgb(data,parula))
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.

Antworten (1)

Cris LaPierre
Cris LaPierre am 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=1:size(img,2);
y=1:size(img,1);
[X,Y] = meshgrid(x,y);
Z = sind(X) + cosd(Y);
surf(X,Y,Z,img,'EdgeColor','none')

Community Treasure Hunt

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

Start Hunting!

Translated by