필터 지우기
필터 지우기

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

조회 수: 15 (최근 30일)
Megan LaMonica
Megan LaMonica 2023년 1월 11일
답변: Cris LaPierre 2023년 1월 11일
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.

답변 (1개)

Cris LaPierre
Cris LaPierre 2023년 1월 11일
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')

카테고리

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