3D Plotting with Vectors and Meshgrid
Show older comments
I want to create a 3D plot for something that is very similar to the example in meshgrid (below)
[X,Y] = meshgrid(-2:.2:2, -2:.2:2);
Z = X .* exp(-X.^2 - Y.^2);
surf(X,Y,Z)
Basically, I have vectors in my definition of Z and I am unsure about how to handle this. My definition of Z is
Z = mean((S - (X*A+Y)).^2);
S and A are vector quantities so this line doesn't make sense. The only solution I can think of here is to create a 3D meshgrid where the third dimension of the length of my vectors S and A (they are the same length). I think this could get tricky though. Is there an easier way.
Example: I have two vectors P and Q like these:
P = [zeros(1, 30) ones(1,40) zeros(1,30)] + .1*randn(1,100);
Q=3.4.*([zeros(1, 30) ones(1,40) zeros(1,30)] + .1.*randn(1,100))+5.3;
Because Q is scaled and offset finding the mean squared error between them directly is pointless.
MSE = mean((P-Q).^2);
this MSE doesn't mean much because Q is offset and scaled. I re-define MSE:
myMSE = mean((P-(a*Q+b)).^2)
where a and b are scalars. What I would like to do is plot myMSE as a function of both a and b. IE a is on the x-axis and b is on the y axis and Z is the value for myMSE.
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Performance 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!