Using surf to compare three vectors
3 views (last 30 days)
Show older comments
I'd like to compare three vectors graphically, and I think surf is the function to use.
In exploring surf, I can't wrap my head around how to implement meshgrid. The variables I want to compare are all vectors of the same length, yet Z needs to be a matrix according to the documentation, and meshgrid is somehow involved.
X: 7627x1, range: 420 to 480
Y: 7627x1, range: -30 to -8
Z: 7627x1, range: 0.8 to 4.2
In all of the examples on the surf documentation page, the Z-axis is always symmetrical about 0. Can you use surf where the Z-axis minimum is 0?
If surf isn't what I want to use to do this, please point me in the right direction. I've also seen rectangular colormaps using filled in color gradients (i.e., not points or lines) comparing X vs. Y vs. Z (represented by color). Obviously, there's some interpolation happening in both this 2-d colormap as well as surf.
As a sample, how does one produce something like this sample, which is comparing X vs. Y vs. Z (denoted with a color ramp).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165740/image.png)
Thanks, everybody. As always, the help is much appreciated.
1 Comment
John D'Errico
on 3 Jul 2017
Nope. Surf is NOT the tool to use here. Surf is not a tool used to compare vectors graphically. In fact, I don't even know what you mean by that.
There is NO requirement with surf that the z axis have any special limits.
If you want to compare three vectors, just use plot. WTP?
Surf is used to plot a surface. Is that what you really want to do?
Accepted Answer
Image Analyst
on 4 Jul 2017
Just make up a 2-D array with the number of rows and columns you want, then assign the z values to it. Then display it. Like, is this what you want?
% X: 7627x1, range: 420 to 480
% Y: 7627x1, range: -30 to -8
% Z: 7627x1, range: 0.8 to 4.2
columns = 7627; % X
rows = 7627; % Y
indexedimage = zeros(rows, columns); % Zero image, or...
indexedimage = 0.8 + (4.2-0.8)*rand(rows, columns); % random image
xData = linspace(420, 480, columns);
yData = linspace(-30, -8, rows);
imshow(mat2gray(indexedimage), 'XData', xData, 'YData', yData);
colormap(gca, hsv(256));
colorbar;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177314/image.png)
More Answers (1)
KSSV
on 4 Jul 2017
x = linspace(420,480,7627) ;
y = linspace(-30,-8,7627) ;
z = linspace(0.8,4.2,7627) ;
figure
hold on
plot(x,'r') ;
plot(y,'b') ;
plot(z,'g') ;
legend([{'X'},{'Y'},{'Z'}])
See Also
Categories
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!