Revolving a 2D plot around its vertical axis to generate 3D surface
10 次查看(过去 30 天)
显示 更早的评论
Asser Abdelgawad
2022-6-13
While this solution is helpful, the usage of repmat makes it so that the values are repeated and not unique. What I would like to do is convert to polar and rotate without repeating values. Is there a way to execute the revolution without repmat?
2 个评论
Asser Abdelgawad
2022-6-13
Hmm but is there a way to do it besides repmat? For instance:
theta = linspace(0, 2*pi, 100);
for i=1:100
theta=pi/180*theta(i);
t_theta=X.*cos(theta)+Y.*sin(theta);
vals=interp1(x , y, t_theta(:),'pchip');
end
采纳的回答
Matt J
2022-6-13
18 个评论
Matt J
2022-6-13
编辑:Matt J
2022-6-13
From your comment in the other post
I've tried the cylinder function with all 6 possible orderings of x,y, and z but I cannot get my gaussian function to go from left to right such as in this diagram.
t = linspace(0,1,1000);
r=2*sqrt(-log(t));
[X,Z,Y] = cylinder(r,1000);
surf(X,Y,Z,'EdgeColor','none');
set(gca,'YDir','reverse');
xlabel X; ylabel Y; zlabel Z;
Asser Abdelgawad
2022-6-14
Thank you @Matt J, I appreciate your help. However, my starting function is a Gaussian with the form:
y = e^(-x^2). I don't think it's suitable to use another function because the values aren't the same, though the shape ultimately is. Is there a different approach?
Asser Abdelgawad
2022-6-14
Ah @Matt J, that makes sense! The problem is, in general, this wouldn't work because the sqrt() gives complex results for inputs outside (0,1), which wouldn't work for surf(), right? At least this is the issue I am facing currently.
Matt J
2022-6-14
编辑:Matt J
2022-6-14
this wouldn't work because the sqrt() gives complex results for inputs outside (0,1),
For z<0, sqrt(z) will give complex numbers, but you shouldn't ever need to evaluate in that range. You should only need to evaluate for z in the range of values that the Gaussian lobe can take.
Asser Abdelgawad
2022-6-14
Sorry what does that mean exactly? In my case, for instance, I have input values from [-300,300] let's say. They are perfectly valid input values for the standard gaussia lobe because it is defined for all x inR. This wouldn't work, correct?
Asser Abdelgawad
2022-6-14
I'm still not sure what you mean. If you were to do: linespace(0,2,1000), the whole thing falls apart because complex numbers are introduced. In my case, for instance:
f = fit(x, y, 'gauss1');
vals = coeffvalues(f);
x0 = x; %where x ranges randomly from -300 to 300, so it is outside the interval (0,1)
y0 = vals(3)*sqrt(-log(x0/vals(1))) + vals(2); %inverse of gaussian f
[x,z,y] = cylinder(y0,100);
surf(x,y,z) %here i get an error about complex numbers
Am I doing something wrong here? Or does the method indeed fall apart?
Matt J
2022-6-14
r=linspace(-300,300,100)';
y=4*exp(-(r/30).^2);
f = fit(r, y, 'gauss1','Lower',[0,0,0],'Upper',[inf,0,inf]);
vals = num2cell(coeffvalues(f));
[a,b,c]=deal(vals{:})
a = 4.0000
b = 0
c = 30.0000
y0=linspace(0,a,1000);
r0 = c*sqrt(-log(y0/a)); %inverse of gaussian f
[X,Z,Y] = cylinder(r0,1000);
surf(X,Y,Z,'EdgeColor','none');
set(gca,'YDir','reverse');
xlabel X; ylabel Y; zlabel Z;
Asser Abdelgawad
2022-6-14
Hi @Matt J. I truly appreciate your help throughout this process. However, this method doesn't create the full rotation as needed. If you look at my earlier comments, given that the x-values range from [-300, 300], the x and z values should do so as well (see the two graphs I posted). This isn't the case here. I've also attached my dataset here. Ideally, there would be two axes taking the values of "freq" and the vertical axis taking the values of "MTF_fit" accordingly
Matt J
2022-6-14
Your .mat attachment contains a million variables. I can't decipher what everything means there.
In any case, you can make the range of the plot extend out to 300 if you wish. I now show this below. However, I don't see why, just because you have data at a radius of 300, you would require the fit to be plotted there as well. A Gaussian lobe at a radius of more than 4 standard deviations is essentially zero, and is not very informative.
r=linspace(-300,300,100)';
y=4*exp(-(r/30).^2);
f = fit(r, y, 'gauss1','Lower',[0,0,0],'Upper',[inf,0,inf]);
vals = num2cell(coeffvalues(f));
[a,b,c]=deal(vals{:})
a = 4.0000
b = 0
c = 30.0000
y0=linspace(f(300),a,1000);
r0 = c*sqrt(-log(y0/a)); %inverse of gaussian f
[X,Z,Y] = cylinder(r0,1000);
surf(X,Y,Z,'EdgeColor','none');
set(gca,'YDir','reverse');
xlabel X; ylabel Y; zlabel Z;
Asser Abdelgawad
2022-6-16
Hi @Matt J. Thank you, this is exactly the shape I was looking for. The values in the y-axis are unfortunately repeated across the rows still, which makes for a 1D gaussian instead of the desired wider-base 2D gaussian when I perform ifft2() on this shape. This is my error when I first asked the question, as I thought cylinder() would achieve something different from repmat, but I was mistaken. Either way, thank you for your help. I will look into another method.
Matt J
2022-6-16
It doesn't really make sense to use ifft on a Gaussian. The (inverse) Fourier Transform of a Gaussian has a closed form analytical solution.
Asser Abdelgawad
2022-6-16
From my understanding, it is standard practice for my image processing application, which is performing the inverse FFT on the modulation transfer function in 2D (MTF2) which then gives the Point Spread Function for the imaging system.
Asser Abdelgawad
2022-6-16
So the IFFT function yields different results than the analytical inverse fourier transform? I did know that to be honest. OK, so you're saying I'm better off coding the transform function from scratch, with the integral and all?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)