# hold value of multiplication of two scalar vector

조회 수: 3(최근 30일)
Arijet Sarker 2018년 6월 24일
답변: VBBV 2021년 10월 24일
gamma = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] tao = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1]
for i = 1:10
for j = 1:10
lm = gamma(i) * tao(j)
end
end
I want all the values of gamma * tao in lm variable. But, I am only getting lm=1.

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

### 답변(2개)

Stephen 2018년 6월 24일
편집: Stephen 2018년 6월 24일
Simpler (for R2016b and later):
gamma(:) .* tao
or for older versions:
bsxfun(@times,gamma(:),tao)
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

VBBV 2021년 10월 24일
gamma = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
tao = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
for i = 1:10
for j = 1:10
lm(i,j) = gamma(i) * tao(j);
end
end
lm
lm = 10×10
0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.2000 0.0300 0.0600 0.0900 0.1200 0.1500 0.1800 0.2100 0.2400 0.2700 0.3000 0.0400 0.0800 0.1200 0.1600 0.2000 0.2400 0.2800 0.3200 0.3600 0.4000 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500 0.4000 0.4500 0.5000 0.0600 0.1200 0.1800 0.2400 0.3000 0.3600 0.4200 0.4800 0.5400 0.6000 0.0700 0.1400 0.2100 0.2800 0.3500 0.4200 0.4900 0.5600 0.6300 0.7000 0.0800 0.1600 0.2400 0.3200 0.4000 0.4800 0.5600 0.6400 0.7200 0.8000 0.0900 0.1800 0.2700 0.3600 0.4500 0.5400 0.6300 0.7200 0.8100 0.9000 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000
You can simply add indices of for loops to the lm variable as above

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

### Community Treasure Hunt

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

Start Hunting!

Translated by