vector not produced missing some '.' ?

something is wrong with this code
t=0:0.1:1;
g = (0.30/(2*(pi*t^3)^0.5))*exp((-0.30^2)/(4*t));
As the vector g never gets made, I'm sure I need to put some '.' somewhere but I really don't understand this whole '.' stuff

댓글 수: 1

Paulo Silva
Paulo Silva 2011년 4월 7일
Sean answer is great for such cases, also when there's one dot missing matlab tells you what's the operation in the error message:
mtimes % before *
mdivide % before /
mpower % before ^

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

 채택된 답변

Paulo Silva
Paulo Silva 2011년 4월 7일

0 개 추천

t=0:0.1:1;
g = (0.30./(2*(pi*t.^3).^0.5)).*exp((-0.30^2)./(4*t));

추가 답변 (3개)

Sean de Wolski
Sean de Wolski 2011년 4월 7일

1 개 추천

vectorize('g = (0.30/(2*(pi*t^3)^0.5))*exp((-0.30^2)/(4*t))');
A brainless way for us lazies.

댓글 수: 4

Paulo Silva
Paulo Silva 2011년 4월 7일
That's a good one, I must remember it :) +1 vote
but it too lazie, even for me lol
Matt Fig
Matt Fig 2011년 4월 7일
Even better(?) and definitely lazier.
eval(vectorize('g = (0.30/(2*(pi*t^3)^0.5))*exp((-0.30^2)/(4*t))'))
Paulo Silva
Paulo Silva 2011년 4월 7일
... ..- .--. . .-. .-.. .- --.. .. .
Sean de Wolski
Sean de Wolski 2011년 4월 7일
Eval, is the king of MATLAB laziness!

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

Matt Fig
Matt Fig 2011년 4월 7일

0 개 추천

As a general rule when dealing with operations on arrays, use a dot before every one of the three operators:
* / ^
If you do this you will be fine.
David Young
David Young 2011년 4월 7일

0 개 추천

If you don't understand the operators, the most straighforward thing is to use
g = (0.30 ./ (2 .* (pi .* t .^ 3) .^ 0.5)) .* exp((-0.30 .^ 2) ./ (4 .* t));
so that all the operators behave as elementwise operators (which I guess is what you want). If you understand the difference, you can omit some of the dots, but they do no harm.
It's not all that hard really: *, / and ^ carry out matrix operations (like matrix multiplication, as defined here), while .*, ./ and .^ operate point by point on the elements of the matrices.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by