How can I turn the following code to a surface plot

function Visualize2(X, Y, E, F, k)
if k==4
k1=2; k2=2;
elseif k==2
k1=1; k2=2;
end
figure;
X=X'; Y=Y'; E=E'; F=F';
%Show the original manifolds
subplot(k1,k2,1);
plot3(X(:,1), X(:,2), X(:,3),'r-', 'LineWidth',.5);
hold on;
plot3(Y(:,1), Y(:,2), Y(:,3),'b-', 'LineWidth',.5);
title({['(A) Before Alignment']});
xlabel('X', 'FontSize',12, 'FontWeight', 'bold');
ylabel('Y', 'FontSize',12, 'FontWeight', 'bold');
zlabel('Z', 'FontSize',12, 'FontWeight', 'bold');
% 3D
subplot(k1,k2,4);
plot3(E(:,1), E(:,2), E(:,3),'r-', 'LineWidth',.5);
hold on;
plot3(F(:,1), F(:,2), F(:,3),'b-', 'LineWidth',.5);
title({['(B) After 3D Alignment']});
xlabel('X', 'FontSize',12, 'FontWeight', 'bold');
ylabel('Y', 'FontSize',12, 'FontWeight', 'bold');
zlabel('Z', 'FontSize',12, 'FontWeight', 'bold');
if k==4
% 2D
subplot(k1,k2,3);
plot(E(:,1), E(:,2), 'r-', 'LineWidth',.5);
hold on;
plot(F(:,1), F(:,2), 'b-', 'LineWidth',.5);
title({['(C) After 2D Alignment']});
xlabel('X', 'FontSize',12, 'FontWeight', 'bold');
ylabel('Y', 'FontSize',12, 'FontWeight', 'bold');
zlabel('Z', 'FontSize',12, 'FontWeight', 'bold');
% 1D
subplot(k1,k2,2);
plot(E(:,1), 'r-', 'LineWidth',.5);
hold on;
plot(F(:,1), 'b-', 'LineWidth',.5);
title({['(D) After 1D Alignment']});
xlabel('X', 'FontSize',12, 'FontWeight', 'bold');
ylabel('Y', 'FontSize',12, 'FontWeight', 'bold');
zlabel('Z', 'FontSize',12, 'FontWeight', 'bold');
end
end

10 件のコメント

darova
darova 2020 年 1 月 18 日
Use griddata
Zain Khaliq
Zain Khaliq 2020 年 1 月 18 日
編集済み: Zain Khaliq 2020 年 1 月 18 日
instead of subplot ? Im relativly new to this and Im not familiar with the sintax. Like what parts would I have to edit in this case ? Sorry I have a paper due tonight and Ive been trying to figure this out for almost 2 days now and keep on getting errors
darova
darova 2020 年 1 月 18 日
Try this
title('(A) Before Alignment');
Instead of
title({['(A) Before Alignment']});
Its faster
Zain Khaliq
Zain Khaliq 2020 年 1 月 18 日
This is the picutre I have and I am trying to convert this to a 3d surface plot beacuse my professsor doesnt like this representations and wants me to show this in a way so it wiuld look somthing like this http://www.peteryu.ca/tutorials/matlab/image_in_3d_surface_plot_with_multiple_colormaps .
I tired everything but I just cant code it, I got this from github where I used my data to play around with the code, but i cant seem to change it to a 3d surface plot
Walter Roberson
Walter Roberson 2020 年 1 月 18 日
You should use scatteredInterpolant() to create your 3D plots.
F = scatteredInterpolant(X(:,1), X(:,2), X(:,3));
[xq1, xq2] = meshgrid(-5:.1:5); %use an appropriate range of values and spacing
xq3 = F(xq1, xq2);
mesh(xq1, xq2, xq3)
Zain Khaliq
Zain Khaliq 2020 年 1 月 19 日
Hi so your solution did work however how can I combined both of these into one graph :
%Show the original manifolds
subplot(k1,k2,1);
plot3(X(:,1), X(:,2), X(:,3),'r-', 'LineWidth',.5);
hold on;
plot3(Y(:,1), Y(:,2), Y(:,3),'b-', 'LineWidth',.5);
title({['(A) Before Alignment']});
xlabel('X', 'FontSize',12, 'FontWeight', 'bold');
ylabel('Y', 'FontSize',12, 'FontWeight', 'bold');
zlabel('Z', 'FontSize',12, 'FontWeight', 'bold');
Walter Roberson
Walter Roberson 2020 年 1 月 19 日
F1 = scatteredInterpolant(X(:,1), X(:,2), X(:,3));
[xq1, xq2] = meshgrid(-5:.1:5); %use an appropriate range of values and spacing
xq3 = F1(xq1, xq2);
mesh(xq1, xq2, xq3);
hold on
F2 = scatteredInterpolant(Y(:,1), Y(:,2), Y(:,3));
[yq1, yq2] = meshgrid(-5:.1:5); %use an appropriate range of values and spacing
yq3 = F2(yq1, yq2);
mesh(yq1, yq2, yq3);
hold off
Zain Khaliq
Zain Khaliq 2020 年 1 月 19 日
編集済み: Zain Khaliq 2020 年 1 月 19 日
Thank you so much, one last thing I promise how can I add different color for (X(:,1), X(:,2), X(:,3)); and (Y(:,1), Y(:,2), Y(:,3)); and title for the graph ? And thank you so much for the help
Walter Roberson
Walter Roberson 2020 年 1 月 19 日
mesh(xq1, xq2, xq3, 'r');
and
mesh(yq1, yq2, yq3, 'b');
and
title('(A) Before Alignment')
Zain Khaliq
Zain Khaliq 2020 年 1 月 19 日
the title thing worked, however for color i get the follwoing error :
Error using mesh (line 63)
Property value pairs expected.
Error in Visualize1 (line 69)
mesh(xq1, xq2, xq3,'g');
Error in cmp2All (line 39)
Visualize1(X1, X2, map1(:,1:3)'*X1, map2(:,1:3)'*X2, 4);

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2020 年 1 月 18 日

0 投票

Use surf()
surf(X(:,1), X(:,2), X(:,3), 'EdgeColor', 'none');
If that doesn't work, attach your X, Y, E, F, and k in a .mat file with the paper clip icon.

7 件のコメント

Zain Khaliq
Zain Khaliq 2020 年 1 月 18 日
The file is too large to share, is there a different place where I can send you the project folder ?
Image Analyst
Image Analyst 2020 年 1 月 18 日
If it's too large to share, you're not going to see everything on the surface when it's subsampled for display. So just subsample your data and give us a smaller set of data.
Zain Khaliq
Zain Khaliq 2020 年 1 月 18 日
for some reason, Matlab says I've reach my maximum uploads, but if you go to the follwoing link of the authors of this code : https://sites.google.com/site/changwangnk/home/ma-html
and scroll all the way down to the page there is a folder called Unsupervised.zip.
To run the file you run the cmp2All.m file and to edit the graph, which I was trying to so you have to go to the file called Visualize2.m.
When you run the file you may run into an error beacuse the aurthor in the code forgot to capalize the 'V" in the cmp2All.m file.=, so if you do that you should be able to run it.
The above link is the closest sample data i can provide you with beacuse my data is much more larger.
THANKS IN ADVANCE AND I REALLY HOPE YOU ARE ABLE TO HELP.
Image Analyst
Image Analyst 2020 年 1 月 18 日
What happens if you just do
surf(x, y, z)
using x, y, and z that are appropriate for the data you want?
Zain Khaliq
Zain Khaliq 2020 年 1 月 18 日
it says z not defined
Zain Khaliq
Zain Khaliq 2020 年 1 月 18 日
were you able to see the code? from the link I provided above ? the problem is my professor doesnt like the lines in that graph, beacuse when I replace the authors data with mine and run the code, my data looks like its noise signal, eventho its not so my professor said if you can represent these as surface plot it would look much smoother.
Image Analyst
Image Analyst 2020 年 1 月 19 日
Sorry but I'm not going to be able to have the time to donate to you to delve into this. Basically you need to figure out how to use surf() if you want a surface plot. It should not be hard or beyond your capabilities - you're a smart scientist so I'm sure you can do it.

サインインしてコメントする。

カテゴリ

質問済み:

2020 年 1 月 18 日

コメント済み:

2020 年 1 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by