필터 지우기
필터 지우기

Computing powers in matlab

조회 수: 2 (최근 30일)
mark
mark 2014년 1월 16일
댓글: Walter Roberson 2014년 1월 17일
find A whose ith element is A = ( 2.^i ) X ./ Y .... where X and Y are vectors of equal length
without looping. ie. X = [1 2 3] Y = [4 5 6].
I know how to do X ./ Y but the ith element of (2.^i) is confusing me and I do not know how to do it without looping. Thanks
Edit. Thank you 2.^(1:length(x)) worked. What if it was -2 instead of 2??? I tried fooling around with it but I had no luck

답변 (3개)

Andreas Goser
Andreas Goser 2014년 1월 16일

Mischa Kim
Mischa Kim 2014년 1월 16일
편집: Mischa Kim 2014년 1월 16일
Does this do it?
X = [1 2 3]; Y = [4 5 6];
A = (2.^sort(randperm(length(X)))).*X./Y
A =
0.5000 1.6000 4.0000
  댓글 수: 1
Walter Roberson
Walter Roberson 2014년 1월 16일
A little obfuscation to start the day right ;-)

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


Walter Roberson
Walter Roberson 2014년 1월 16일
  댓글 수: 4
Mischa Kim
Mischa Kim 2014년 1월 16일
Ok, I understand. For the vector size portion, I have to admit, I tried to come up with a challenge for myself.
Walter Roberson
Walter Roberson 2014년 1월 17일
What if it was -2, mark asked.
(-2).^(1:length(X))

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

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by