Hey all, I am trying to plot a 4d plot( meaning 3 axis and 1 color) , I have looked at scatter3, mesh ,plot4d etc. but i was having trouble because part of my data is matrices. I am attaching the code below. To summaries my problem I have got: # Vx-[1*N]; # Vy-[1*N], # cont(:,:,1)-[N*N], # cont(:,:,2)-[N*N] What i want to get is a surface with Vx,Vy,cont(:,:,1) which colors change according to cont(:,:,2) any ideas how to do that? Thanks a lot! Naty
clc
clear all
close all
syms Vy Vx g theta1 r0 t theta0 d sigma eps sign
V0=[Vx,Vy];
t_impact=(d-r0*cos(theta0)-r0*cos(theta1))/Vx;
V_impact_minus=[Vx;Vy-g*t_impact];
R=[cos(theta1+pi/2) -sin(theta1+pi/2);sin(theta1+pi/2) cos(theta1+pi/2)];% Transformation Matrix
V_impact_P_Pre=R.'*V_impact_minus;% Transfrom from X,Y to Tanginet,Normal
V_impact_P_Post=[V_impact_P_Pre(1);-eps*V_impact_P_Pre(2)+sigma];
V_impact_plus=(R*V_impact_P_Post);
%Numerical Expression
m=1.548;
r0=0.193;
g=1.478;
theta0=pi/4;
Vx_target=-1;
Vy_target=0; % Fixed Ponint Valus.
eps=.7;
d=0.54;
N=10;
Vx_vec=linspace(-3,-0.1,N);
Vy_vec=linspace(-2,2,N);
% theta1=cont(1);
% sigma=cont(2);
cont=zeros(N,N,2);
for ii=1:length(Vx_vec)
for jj=1:1:length(Vy_vec)
Vx=Vx_vec(ii);
Vy=Vy_vec(jj);
myfun=matlabFunction(subs(V_impact_plus'-[Vx_target;Vy_target]'));
[cont(ii,jj,:),fval(ii,jj,:)]=fsolve(@(x) call_on(myfun, x),pi/3,0.3]);
end
end
[X,Y]=meshgrid(Vx_vec,Vy_vec);
scatter3(X(:),Y(:),cont(:,:,1))

1 commentaire

Sven
Sven le 19 Août 2013
Please make sure your code is copy/paste runnable. At the moment there is an extra ] in your fsolve arguments, and after removing that I get the error:
Undefined function 'call_on' for input arguments of type 'function_handle'.
Error in @(x)call_on(myfun,x)
Error in fsolve (line 218)
fuser = feval(funfcn{3},x,varargin{:});

Connectez-vous pour commenter.

 Réponse acceptée

Sven
Sven le 19 Août 2013

1 vote

Naty, as per the comment above I can't replicate your exact data, but here's an example that should show you how to make the figures you're looking for.
% Make some 4D data in X, Y, height, colour:
% Each point now has an X, Y, Z (height), and C (colour) value
[X,Y,Z] = peaks(51); % 51-by-51 Z as a function of X, Y
C = membrane(1,25); % Colour
% Show the data as a surface plot
figure, surf(X,Y,Z,C), colorbar
% Show the data as a scatter3 plot
figure, scatter3(X(:),Y(:),Z(:),6,C(:),'filled'), colorbar
So, according to your problem description:
What i want to get is a surface with Vx,Vy,cont(:,:,1).
Which colors change according to cont(:,:,2) any ideas how to do that?
You can just do this:
[X,Y]=meshgrid(Vx_vec,Vy_vec);
Z = cont(:,:,1);
C = cont(:,:,2);
And then just call syntax like my example above:
figure, surf(X,Y,Z,C), colorbar
figure, scatter3(X(:),Y(:),Z(:),6,C(:),'filled'), colorbar
Did that solve it for you?

Plus de réponses (2)

francesco
francesco le 8 Nov 2013

0 votes

great, is it possible to sum two plots?
chetan desai
chetan desai le 5 Avr 2015
Modifié(e) : chetan desai le 5 Avr 2015

0 votes

what should be done if i am having C as a 3d matrix in above case ??

Catégories

En savoir plus sur Discrete Data Plots dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by