現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Revolving a 2D plot around its vertical axis to generate 3D surface
17 ビュー (過去 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;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1031310/image.png)
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;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1032695/image.png)
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;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1032740/image.png)
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 で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)