Plotting 4d data with matrices.
Show older comments
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 Comment
Sven
on 19 Aug 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{:});
Accepted Answer
More Answers (2)
francesco
on 8 Nov 2013
0 votes
great, is it possible to sum two plots?
chetan desai
on 5 Apr 2015
Edited: chetan desai
on 5 Apr 2015
0 votes
what should be done if i am having C as a 3d matrix in above case ??
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!