File Exchange

image thumbnail

Plot multiple surfaces multisurf(x,y,z,col​or)

version 1.0.0.0 (1.71 KB) by Alessandro Masullo
Plot multiple surfaces in the same figure, with different colors

4 Downloads

Updated 08 Jun 2016

View License

% MULTISURF(x,y,z,color) plots multiple surfaces with different colors in
% the same figure. The variables x, y and z must be cell array, each element
% containing the data to be plotted. The variable color must be a cell
% array containing the colors of the surfaces, expressed as letter or
% vectors 1x3.
%
% Additional output h = MULTISURF(x,y,z,color) returns a vector
% containing the handles to each surface object.
%
% Example:
% [xs,ys] = meshgrid(1:0.1:2*pi);
% x = {xs xs xs};
% y = {ys ys ys};
% z = {sin(xs) sin(xs/2) sin(xs/10)};
% color = {'r','g',[0 0 1]};
% multisurf(x,y,z,color)
%
% Author: Alessandro Masullo 2015
% http://www.bristol.ac.uk/engineering/people/alessandro-masullo
The code works by changing the CData parameter of the surfaces so that each of them has a unique constant value of CData. A specific colormap created using the user input colors allows different colors for different surfaces.

Cite As

Alessandro Masullo (2020). Plot multiple surfaces multisurf(x,y,z,color) (https://www.mathworks.com/matlabcentral/fileexchange/57550-plot-multiple-surfaces-multisurf-x-y-z-color), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

Hello, is it possible to create a multisurf plot if I have a grid of this type?

L=10;
B=3;
nx = 100;
ny=380;
x = linspace(0,L,nx+1);
y = linspace(0,B,ny+1);

and I have z value which is the union of three matrix, of this type:
z =

1×3 cell array

{101×381 double} {101×381 double} {101×381 double}

How can I do that? Thank you.

zdenky

Terrance Nearey

Thank you. I think your line:
map = reshape(cell2mat(color),[],3);
should be changed to
map = reshape(cell2mat(color),3,[])' ;
It's amazing how hard MATLAB makes it to color surfaces of surface plots uniformly. (Though its easy for some very nice more complex plots.) I don't know why a single color character or 1 x 3 RGB vector as the C argument just doesn't just produce surfaces with the same color on each face.

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: freezeColors / unfreezeColors, export_fig

Community Treasure Hunt

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

Start Hunting!