I have 3, 10 x 1 arrays. The first array is the x-position. The second array is the y-position. The third array is the indent depths as a function of the x and y positions. I want to create a 2D color plot with an X and Y axis and then the Z axis would be the different colors along the area of the x, y surface. Is there a way to do something like this? I want for different colors to represent different indent depths. I dont want this to be a 3D plot.
Thank you.

 Akzeptierte Antwort

Star Strider
Star Strider am 25 Apr. 2020

0 Stimmen

Your problem statement appears to have eliminated most solutions.
Try this:
x = rand(10,1);
y = rand(10,1);
z = rand(10,1);
xv = linspace(min(x), max(x), numel(x));
yv = linspace(min(y), max(y), numel(y));
[X,Y] = ndgrid(xv, yv);
Z = griddata(x, y, z, X, Y);
figure
surf(X, Y, Z)
view(0,90)
% view(90,0)
It creates a 3D surface, then orients it with view to create a 2D plot.

4 Kommentare

birdnerd007
birdnerd007 am 25 Apr. 2020
@Star Strider - Thanks for your reply. This seems to be in the right direction....
Perhaps I explained it incorrectly, my apologies. There are 10 tests that happened. Each test represents and indent at a specific depth that took place at a certain x,y position. There is only 1 solution for each indent and I want to be able to represent by color the depth associated with that test. I don't know if that makes sense? The data is discrete.
My pleasure!
The scatter function may be more appropriate (assuming that I unserstand what you want):
x = rand(10,1);
y = rand(10,1);
z = rand(10,1);
figure
scatter(x, y, [], z, 'filled')
grid
Here, the ‘z’ value assigns the colour. (The third scatter argument sets the marker size. I set it to use the default value by passing the empty array [] in that position.) Experiment with different expressions for the colour argument to get the result you want.
birdnerd007
birdnerd007 am 25 Apr. 2020
Perfect! Thanks a million!
Star Strider
Star Strider am 25 Apr. 2020
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by