Mexican Hat function plot help

조회 수: 12 (최근 30일)
Jesse
Jesse 2011년 10월 5일
댓글: Palguna Gopireddy 2022년 4월 8일
Hello all,
I'm trying to plot a certain Mexican Hat function (other than the one they provide in MATLAB), but I'm getting the matrix dimensions must agree when I define psi. I tried everything to fix the code, but no luck. Can someone advise?
I know some code is repetitive, but I need them in other areas of my code.
dXs = 1;
x = [-20,20];
SamplingScale = [1, dXs, 4, 20 ,40];
Range = SamplingScale;
HalfRange = Range/2;
Sigma = HalfRange/4;
SigmaSq = Sigma.^2;
for i = 1:length(x)
psi = (2/(sqrt(3)*Sigma)*pi^(-0.25))*(1-(i^2/Sigma^2))*(e^(-i^2/2*SigmaSq));
end
plot (psi)
Thanks again!

채택된 답변

the cyclist
the cyclist 2011년 10월 5일
I did two main things with your code (pasted below):
  1. Added a lot of "dot''s to the line of code in your loop. When you have vectors, and you want to do operation on those vectors element-by-element, you need to add those dots, so that MATLAB does not think you want to do matrix operations (e.g. matrix multiply or matrix inverse).
  2. Added the line "e = exp(1)" to your code. MATLAB does not have "e" predefined. You could also have used the exp() function instead of your syntax.
You might want to read the "Getting Started" guide: http://www.mathworks.com/help/techdoc/learn_matlab/bqr_2pl.html
dXs = 1;
x = [-20,20];
SamplingScale = [1, dXs, 4, 20 ,40];
Range = SamplingScale;
HalfRange = Range/2;
Sigma = HalfRange/4;
SigmaSq = Sigma.^2;
e = exp(1);
for i = 1:length(x)
psi = (2./(sqrt(3)*Sigma)*pi^(-0.25)).*(1-(i^2./(Sigma.^2))).*(e.^(-i^2./(2*SigmaSq)));
end
plot (psi)
  댓글 수: 1
Jesse
Jesse 2011년 10월 5일
Hmm, apparently I didn't try everything!
Thanks cyclist!

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

추가 답변 (1개)

Palguna Gopireddy
Palguna Gopireddy 2022년 3월 31일
What is the mexihat equation used in matlab. In original equation there is no term called [lb,ub].
  댓글 수: 3
Ramiro Saldaña Acosta
Ramiro Saldaña Acosta 2022년 4월 8일
I suggest lb=-5, ub=5, N=50
Palguna Gopireddy
Palguna Gopireddy 2022년 4월 8일
Thanks.Got it.any function can be know seen by pressing right click on it and opening it.
But for chebwin function one of the lines is 'chebwinx' which can't be opened. They said it is a MEX file. Do you know any way to open and see a MEX file in matlab.

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

카테고리

Help CenterFile Exchange에서 Formatting and Annotation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by