Filter löschen
Filter löschen

how to plot multiple implicit quadratic surfaces at once ?

3 Ansichten (letzte 30 Tage)
Itzik Ben Shabat
Itzik Ben Shabat am 11 Aug. 2014
Beantwortet: Yu Jiang am 11 Aug. 2014
so i wrote the following code to plot a single quadratic implicit surface based on the ezimplot3 function from matlab exchange.
In order to plot multiple surfaces i have to run this function in a loop which takes a lot of time.
Is there a way to do this using vectors and matrices ? (which i know is much faster).
I mean that here C would be a matrix of coefficient (each row representing a different quadratic) and Domain would also be a matrix (each row will contain the domain of the corresponding quadratic in C). i donw mind that step would remain constant for all surfaces.
function [ model_handle ] = PlotImplicitQuadratcSurface( C,Domain,step )
%PlotImplicitQuadratcSurface plots the implicit quadratic functions dfined
%by the parametes in C
%C: 1x10 vector containing the quadratic coefficients
%Domain: 1x6 vector containing the limits in which to plot the quadratic
%model_handle: a handle to the patch object
%initialize variables
xm= linspace(Domain(1),Domain(2),step);
ym = linspace(Domain(3),Domain(4),step);
zm = linspace(Domain(5),Domain(6),step);
[X,Y,Z] = meshgrid(xm,ym,zm);
model_handle = patch(isosurface(X,Y,Z,fvalues,0)); % "patch" handles the structure...
% sent by "isosurface"
isonormals(X,Y,Z,fvalues,model_handle)% Recalculating the isosurface normals based...
% on the volume data
% Aditional graphic details:
alpha(0.7) % adjusting for some transparency
grid on;
axis equal;
lighting gouraud

Antworten (1)

Yu Jiang
Yu Jiang am 11 Aug. 2014
Hi Itzik Ben Shabat
I agree that you could revise the function such that it takes input arguments C and D as matrices with multiple rows. However, you may still need to use a for loop inside the function because not everything here is vectorizable.
For example, the first two arguments in linspace must be scalars. Also, patch will return only one handle, not a vector of handles. isonormal cannot take 4-D matrices as its first three arguments.
Therefore, I think the idea of vectorization may not significantly reduce the execution time of the code. If you would like to find out more details regarding vectorization in MATLAB, please see the documentation via the following link

Community Treasure Hunt

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

Start Hunting!

Translated by