How to convert from plot3 to surf?

조회 수: 17 (최근 30일)
Ege Çetiner
Ege Çetiner 2021년 4월 18일
댓글: Walter Roberson 2021년 4월 19일
Hello!
I want to convert my plot3 graph to surf graph but it says data is too much. Can anyone help me to convert it a surf graph?
Thanks for any response.

채택된 답변

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2021년 4월 18일
You have scattered 3d points, surf is made for rectangular grid data. An alternative is to use a function specifically for scattered points, which in matlab is the trisurf function.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
format short g;
format compact;
fontSize = 18;
fprintf('Beginning to run %s.m ...\n', mfilename);
Beginning to run LiveEditorEvaluationHelperEeditorId.m ...
counter= 0;
counter1=0;
for ky=0:1:1000
for i=0:1:89
angle=deg2rad(i);
c=ky*cos(angle);
k1ky=0.85*ky;
p1= 105*sin(angle)+105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p2= -105*sin(angle)+105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p3= 105*sin(angle)-105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p4= -105*sin(angle)-105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
es1 = (0.003*p1)/c;
es2 = (0.003*p2)/c;
es3 = (0.003*p3)/c;
es4 = (0.003*p4)/c;
ss1 = max(min(es1*200000,420),-420);
ss2 = max(min(es2*200000,420),-420);
ss3 = max(min(es3*200000,420),-420);
ss4 = max(min(es4*200000,420),-420);
fs1 = ss1*100*pi*10^-3;
fs2 = ss2*100*pi*10^-3;
fs3 = ss3*100*pi*10^-3;
fs4 = ss4*100*pi*10^-3;
fs1y = fs1*0.105;
fs1x = fs1*-0.105;
fs2y = fs2*0.105;
fs2x = fs2*0.105;
fs3y = fs3*-0.105;
fs3x = fs3*-0.105;
fs4y = fs4*-0.105;
fs4x = fs4*0.105;
Tfs = fs1+fs2+fs3+fs4;
Msy = fs1x+fs2x+fs3x+fs4x;
Msx = fs1y+fs2y+fs3y+fs4y;
if k1ky <= 300
if 300*tan(angle)< k1ky
Area= (((k1ky-(300*tan(angle)))+k1ky)/2)*300;
Centroidx= (300*tan(angle)*150*(-50))/Area;
Centroidy= (((150-((k1ky-300*tan(angle))/2)) *300* (k1ky-300*tan(angle)))+ (300*tan(angle)*150* (150-((k1ky-300*tan(angle))+(300*tan(angle)/3)))))/Area;
else
Area= ((k1ky*cot(angle))*k1ky)/2;
Centroidx= (((k1ky*cot(angle))/3)-150);
Centroidy= 150-(k1ky/3);
end
else
if 300*tan(angle)<= k1ky
if k1ky-300*tan(angle) >= 300
Area = 90000;
Centroidx = 0;
Centroidy = 0;
else
Area= 90000-(((300-(k1ky-(300*tan(angle))))*((300-(k1ky-(300*tan(angle))))*cot(angle)))/2);
Centroidx = -((150-(((300-(k1ky-(300*tan(angle))))*cot(angle))/3))*(90000-Area))/Area;
Centroidy = -((((300-(k1ky-(300*tan(angle))))/3)-150)*(90000-Area))/Area;
end
else
Area= (k1ky*cot(angle))*300-((300*cot(angle))*150);
Centroidx = ((((k1ky*cot(angle))*300)*(((k1ky*cot(angle))/2)-150)) - (((300*cot(angle))*150)*((k1ky*cot(angle))-((300*cot(angle))/3)-150)))/Area;
Centroidy = -(((300*cot(angle))*150)*-50)/Area;
end
end
fc = 0.85*20*Area*10^-3;
N = max(0,fc+Tfs);
Mx = Msx + fc*Centroidy*10^-3;
My = Msy + fc*Centroidx*10^-3;
counter = counter + 1;
xAll(counter) = Mx;
yAll(counter) = My;
zAll(counter) = N;
end
end
figure
plot3(xAll,-yAll,zAll,'m.');
grid on
hold on
plot3(-yAll,xAll,zAll,'m.');
set(gca, 'CameraPosition', [607.33 607.6 2775.3]);
xlabel('Mx(kNm)')
ylabel('My(kNm)')
zlabel('N(kN)')
figure
nonNANindices = find( ~isnan(yAll) & ~isnan(xAll) & ~isnan(zAll) );
T1 = delaunay(-yAll(nonNANindices)',xAll(nonNANindices)');
Warning: Duplicate data points have been detected and removed.
Some point indices will not be referenced by the triangulation.
T2 = delaunay(xAll(nonNANindices)',yAll(nonNANindices)');
Warning: Duplicate data points have been detected and removed.
Some point indices will not be referenced by the triangulation.
trisurf(T1,-yAll(nonNANindices),xAll(nonNANindices),zAll(nonNANindices)),shading interp
hold on
trisurf(T2,xAll(nonNANindices),-yAll(nonNANindices),zAll(nonNANindices)),shading interp

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 4월 18일
format short g;
format compact;
fontSize = 18;
counter= 0;
counter1=0;
for ky=0:1:1000
for i=0:1:89
angle=deg2rad(i);
c=ky*cos(angle);
k1ky=0.85*ky;
p1= 105*sin(angle)+105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p2= -105*sin(angle)+105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p3= 105*sin(angle)-105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p4= -105*sin(angle)-105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
es1 = (0.003*p1)/c;
es2 = (0.003*p2)/c;
es3 = (0.003*p3)/c;
es4 = (0.003*p4)/c;
ss1 = max(min(es1*200000,420),-420);
ss2 = max(min(es2*200000,420),-420);
ss3 = max(min(es3*200000,420),-420);
ss4 = max(min(es4*200000,420),-420);
fs1 = ss1*100*pi*10^-3;
fs2 = ss2*100*pi*10^-3;
fs3 = ss3*100*pi*10^-3;
fs4 = ss4*100*pi*10^-3;
fs1y = fs1*0.105;
fs1x = fs1*-0.105;
fs2y = fs2*0.105;
fs2x = fs2*0.105;
fs3y = fs3*-0.105;
fs3x = fs3*-0.105;
fs4y = fs4*-0.105;
fs4x = fs4*0.105;
Tfs = fs1+fs2+fs3+fs4;
Msy = fs1x+fs2x+fs3x+fs4x;
Msx = fs1y+fs2y+fs3y+fs4y;
if k1ky <= 300
if 300*tan(angle)< k1ky
Area= (((k1ky-(300*tan(angle)))+k1ky)/2)*300;
Centroidx= (300*tan(angle)*150*(-50))/Area;
Centroidy= (((150-((k1ky-300*tan(angle))/2)) *300* (k1ky-300*tan(angle)))+ (300*tan(angle)*150* (150-((k1ky-300*tan(angle))+(300*tan(angle)/3)))))/Area;
else
Area= ((k1ky*cot(angle))*k1ky)/2;
Centroidx= (((k1ky*cot(angle))/3)-150);
Centroidy= 150-(k1ky/3);
end
else
if 300*tan(angle)<= k1ky
if k1ky-300*tan(angle) >= 300
Area = 90000;
Centroidx = 0;
Centroidy = 0;
else
Area= 90000-(((300-(k1ky-(300*tan(angle))))*((300-(k1ky-(300*tan(angle))))*cot(angle)))/2);
Centroidx = -((150-(((300-(k1ky-(300*tan(angle))))*cot(angle))/3))*(90000-Area))/Area;
Centroidy = -((((300-(k1ky-(300*tan(angle))))/3)-150)*(90000-Area))/Area;
end
else
Area= (k1ky*cot(angle))*300-((300*cot(angle))*150);
Centroidx = ((((k1ky*cot(angle))*300)*(((k1ky*cot(angle))/2)-150)) - (((300*cot(angle))*150)*((k1ky*cot(angle))-((300*cot(angle))/3)-150)))/Area;
Centroidy = -(((300*cot(angle))*150)*-50)/Area;
end
end
fc = 0.85*20*Area*10^-3;
N = max(0,fc+Tfs);
Mx = Msx + fc*Centroidy*10^-3;
My = Msy + fc*Centroidx*10^-3;
counter = counter + 1;
xAll(counter) = Mx;
yAll(counter) = My;
zAll(counter) = N;
end
end
figure
plot3(xAll,-yAll,zAll,'m.');
grid on
hold on
plot3(-yAll,xAll,zAll,'m.');
set(gca, 'CameraPosition', [607.33 607.6 2775.3]);
xlabel('Mx(kNm)')
ylabel('My(kNm)')
zlabel('N(kN)')
min(zAll), max(zAll)
ans = 0
ans = 2057.8
figure
N = 50;
C1a = xAll.';
C2a = -yAll.';
C3a = zAll.';
mask = isfinite(C1a) & isfinite(C2a) & isfinite(C3a);
C1a = C1a(mask); C2a = C2a(mask); C3a = C3a(mask);
xmin = min(C1a); xmax = max(C1a);
xvec = linspace(xmin, xmax, N);
ymin = min(C2a); ymax = max(C2a);
yvec = linspace(ymin, ymax, N);
[X, Y] = meshgrid(xvec, yvec);
F = scatteredInterpolant(C1a, C2a, C3a, 'natural');
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Z = F(X, Y);
surf(X, Y, Z, 'edgecolor', 'none')
xlabel('Mx(kNm)')
ylabel('My(kNm)')
zlabel('N(kN)')
hold on
min(C3a), max(C3a)
ans = 0
ans = 2057.8
min(Z(:)), max(Z(:))
ans = -7.7831e+06
ans = 5913.8
C1b = -yAll.';
C2b = xAll.';
C3b = zAll.';
mask = isfinite(C1b) & isfinite(C2b) & isfinite(C3b);
C1b = C1b(mask); C2b = C2b(mask); C3b = C3b(mask);
xmin = min(C1b); xmax = max(C1b);
xvec = linspace(xmin, xmax, N);
ymin = min(C2b); ymax = max(C2b);
yvec = linspace(ymin, ymax, N);
[X, Y] = meshgrid(xvec, yvec);
F = scatteredInterpolant(C1b, C2b, C3b, 'natural');
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
surf(X, Y, Z, 'edgecolor', 'none')
hold off
xlim auto; ylim auto; zlim auto
set(gca, 'CameraPosition', [607.33 607.6 2775.3]);
min(C3b), max(C3b)
ans = 0
ans = 2057.8
min(Z(:)), max(Z(:))
ans = -7.7831e+06
ans = 5913.8
figure
subplot(3,1,1); histogram(C1a)
subplot(3,1,2); histogram(C2a)
subplot(3,1,3); histogram(C3a)
Your coordinates are very biased, and when sorted into order, is not very continuous. That leads to sharp changes between values, and that leads to really big spurious peaks when you interpolate in 3D.
  댓글 수: 3
Walter Roberson
Walter Roberson 2021년 4월 19일
10000 is the histogram count. Your coordinates are not equally distributed, they are mostly very small and very closely packed, but also not very continuous.
Walter Roberson
Walter Roberson 2021년 4월 19일
DELTA = 0.002;
format short g;
format compact;
fontSize = 18;
counter= 0;
counter1=0;
for ky=0:1:1000
for i=0:1:89
angle=deg2rad(i);
c=ky*cos(angle);
k1ky=0.85*ky;
p1= 105*sin(angle)+105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p2= -105*sin(angle)+105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p3= 105*sin(angle)-105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p4= -105*sin(angle)-105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
es1 = (0.003*p1)/c;
es2 = (0.003*p2)/c;
es3 = (0.003*p3)/c;
es4 = (0.003*p4)/c;
ss1 = max(min(es1*200000,420),-420);
ss2 = max(min(es2*200000,420),-420);
ss3 = max(min(es3*200000,420),-420);
ss4 = max(min(es4*200000,420),-420);
fs1 = ss1*100*pi*10^-3;
fs2 = ss2*100*pi*10^-3;
fs3 = ss3*100*pi*10^-3;
fs4 = ss4*100*pi*10^-3;
fs1y = fs1*0.105;
fs1x = fs1*-0.105;
fs2y = fs2*0.105;
fs2x = fs2*0.105;
fs3y = fs3*-0.105;
fs3x = fs3*-0.105;
fs4y = fs4*-0.105;
fs4x = fs4*0.105;
Tfs = fs1+fs2+fs3+fs4;
Msy = fs1x+fs2x+fs3x+fs4x;
Msx = fs1y+fs2y+fs3y+fs4y;
if k1ky <= 300
if 300*tan(angle)< k1ky
Area= (((k1ky-(300*tan(angle)))+k1ky)/2)*300;
Centroidx= (300*tan(angle)*150*(-50))/Area;
Centroidy= (((150-((k1ky-300*tan(angle))/2)) *300* (k1ky-300*tan(angle)))+ (300*tan(angle)*150* (150-((k1ky-300*tan(angle))+(300*tan(angle)/3)))))/Area;
else
Area= ((k1ky*cot(angle))*k1ky)/2;
Centroidx= (((k1ky*cot(angle))/3)-150);
Centroidy= 150-(k1ky/3);
end
else
if 300*tan(angle)<= k1ky
if k1ky-300*tan(angle) >= 300
Area = 90000;
Centroidx = 0;
Centroidy = 0;
else
Area= 90000-(((300-(k1ky-(300*tan(angle))))*((300-(k1ky-(300*tan(angle))))*cot(angle)))/2);
Centroidx = -((150-(((300-(k1ky-(300*tan(angle))))*cot(angle))/3))*(90000-Area))/Area;
Centroidy = -((((300-(k1ky-(300*tan(angle))))/3)-150)*(90000-Area))/Area;
end
else
Area= (k1ky*cot(angle))*300-((300*cot(angle))*150);
Centroidx = ((((k1ky*cot(angle))*300)*(((k1ky*cot(angle))/2)-150)) - (((300*cot(angle))*150)*((k1ky*cot(angle))-((300*cot(angle))/3)-150)))/Area;
Centroidy = -(((300*cot(angle))*150)*-50)/Area;
end
end
fc = 0.85*20*Area*10^-3;
N = max(0,fc+Tfs);
Mx = Msx + fc*Centroidy*10^-3;
My = Msy + fc*Centroidx*10^-3;
counter = counter + 1;
xAll(counter) = Mx;
yAll(counter) = My;
zAll(counter) = N;
end
end
figure
plot3(xAll,-yAll,zAll,'m.');
grid on
hold on
plot3(-yAll,xAll,zAll,'m.');
set(gca, 'CameraPosition', [607.33 607.6 2775.3]);
xlabel('Mx(kNm)')
ylabel('My(kNm)')
zlabel('N(kN)')
min(zAll), max(zAll)
ans = 0
ans = 2057.8
figure
N = 50;
C1a = xAll.';
C2a = -yAll.';
C3a = zAll.';
mask = isfinite(C1a) & isfinite(C2a) & isfinite(C3a) & abs(C1a) <= DELTA & abs(C2a) <= DELTA;
C1a = C1a(mask); C2a = C2a(mask); C3a = C3a(mask);
xmin = min(C1a); xmax = max(C1a);
xvec = linspace(xmin, xmax, N);
ymin = min(C2a); ymax = max(C2a);
yvec = linspace(ymin, ymax, N);
[X, Y] = meshgrid(xvec, yvec);
F = scatteredInterpolant(C1a, C2a, C3a, 'natural');
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Z = F(X, Y);
surf(X, Y, Z, 'edgecolor', 'none')
xlabel('Mx(kNm)')
ylabel('My(kNm)')
zlabel('N(kN)')
hold on
min(C3a), max(C3a)
ans = 0
ans = 2057.8
min(Z(:)), max(Z(:))
ans = -1.0694e+07
ans = 1.0262e+07
C1b = -yAll.';
C2b = xAll.';
C3b = zAll.';
mask = isfinite(C1b) & isfinite(C2b) & isfinite(C3b) & abs(C1b) <= DELTA & abs(C2b) <= DELTA;
C1b = C1b(mask); C2b = C2b(mask); C3b = C3b(mask);
xmin = min(C1b); xmax = max(C1b);
xvec = linspace(xmin, xmax, N);
ymin = min(C2b); ymax = max(C2b);
yvec = linspace(ymin, ymax, N);
[X, Y] = meshgrid(xvec, yvec);
F = scatteredInterpolant(C1b, C2b, C3b, 'natural');
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
surf(X, Y, Z, 'edgecolor', 'none')
hold off
xlim auto; ylim auto; zlim auto
set(gca, 'CameraPosition', [607.33 607.6 2775.3]);
min(C3b), max(C3b)
ans = 0
ans = 2057.8
min(Z(:)), max(Z(:))
ans = -1.0694e+07
ans = 1.0262e+07
figure
subplot(3,1,1); histogram(C1a)
subplot(3,1,2); histogram(C2a)
subplot(3,1,3); histogram(C3a)
figure
scatter3(C1a(:), C2a(:), C3a(:))
So what I have done here at the bottom is to restrict the output to places where the first coordinate (which is either xAll or -yall) has within +/- 0.002, and the second coordinate (which is either -yall or xall) is as well, and look at the output then. Notice from the bottom plot that even within +/- 0.0005 that you have zAll values from 0 to 2047. If you look at the histogram directly above the bottom plot, you will see that in that narrow range, some of the zAll values are "close" to 0, but others are up around 2000.
So you have rapid changes in Z values in a small area.
[C1as,idx] = sort(C1a);
C2as = C2a(idx);
C3as = C3a(idx);
plot3(C1as, C2as, C3as)
You have a number of different places pretty much at (0,0) with different Z values.
Any attempt to interpolate a smooth surface is going to have problems with changes that rapid, unless it does something like an envelope calculation (a binned maximimum intensity projection might help, for example)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by