필터 지우기
필터 지우기

for loop of vector

조회 수: 3 (최근 30일)
fima v
fima v 2020년 5월 6일
댓글: fima v 2020년 5월 6일
Hello, i have a function shown bellow called fun, i want to sample it in a 10.^-6 - 20*10.^-6 interval with 1000 samples as shown bellow.
I have tried to implement it as following with a for loop as shown bellow,but its not iterating over the range where did i go wrong?
Thanks.
c0=2.997*10.^8;
h=6.625*10.^-34;
k=1.38*10.^-23;
n=1;
T=307;
filter=linspace(1,1,1000);
fun=@(lambda)(2*pi.*h.*(c0.^2))./((lambda.^5).*(exp((h.*c0)./(k.*T.*lambda))-1));
for k=linspace(1*10.^-6,20*10.^-6,1000);
plank_vec=fun(k);
end

채택된 답변

KSSV
KSSV 2020년 5월 6일
You need not to use loop for this:
c0=2.997*10.^8;
h=6.625*10.^-34;
k=1.38*10.^-23;
n=1;
T=307;
filter=linspace(1,1,1000);
fun=@(lambda)(2*pi.*h.*(c0.^2))./((lambda.^5).*(exp((h.*c0)./(k.*T.*lambda))-1));
k=linspace(1*10.^-6,20*10.^-6,1000);
plank_vec=fun(k);
If you want to use loop:
plank_vec = zeros(1,length(k)) ;
for i = 1:length(k) ;
plank_vec(i)=fun(k(i));
end
  댓글 수: 1
fima v
fima v 2020년 5월 6일
Thank you very much.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by