필터 지우기
필터 지우기

graphing a gaussian fit of data, invalid use of operator

조회 수: 1 (최근 30일)
todd eliason
todd eliason 2020년 1월 7일
댓글: todd eliason 2020년 1월 7일
I am trying to fit a gaussian curve to some data. dmax, a, Xo, S and dmin are all 1x1 doubles. I want to have the curve centered around Xo. however when I run the code it highlights the "-Xo" and says invalid use of operator. (I am pretty new to coding)
x = xmin:0.001:xmax;
G = (1/dmax)*exp(((a*(x.-Xo)^2))/(2*S^2)) + dmin;
plot(x,G);
  댓글 수: 2
Allen
Allen 2020년 1월 7일
One issue with syntax that am noticing is that you have placed a dot '.' oprerator in front of your minus '-' operator which may be causing the issue. If you are trying to perform element-wise calculations on vectors or arrays, you may need to include the dot '.' operator elsewhere in your equation, but it does not work in front of minus '-' and plus '+' math operators.
If removing the dot '.' operator from the equation does not fix the problem, can you provide a screen-shot of your workspace similar too the example below? Include all variables used in the equation for G, it would help us to understand what you are needing to accomplish.
Capture.PNG
todd eliason
todd eliason 2020년 1월 7일
I fixed the problem by centering my x values on zero before I use the gaussian function. So I used the ".*" operation to square it.

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

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 1월 7일
편집: KALYAN ACHARJYA 2020년 1월 7일
"however when I run the code it highlights the "-Xo" and says invalid use of operator."
G = (1/dmax)*exp(((a*(x.(-Xo))^2))/(2*S^2)) + dmin;
%........................^( ).......

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by