이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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 (한국어)