필터 지우기
필터 지우기

How do I vectorize the following code?

조회 수: 1 (최근 30일)
David
David 2018년 1월 18일
댓글: Matt J 2018년 1월 18일
Hi,
I'm having trouble vectorizing the following code. The result should be a matrix with an upper triangle.
data = 1:1:10;
nn = length(data);
for x = 1:nn
for y = x:nn
X(x,y) = (data(y) - data(x)) / data(x);
end
end
All help gratefully received!

채택된 답변

Matt J
Matt J 2018년 1월 18일
X = triu(data(:)./data(:).' - 1)
  댓글 수: 4
David
David 2018년 1월 18일
That does it! Many thanks.
Matt J
Matt J 2018년 1월 18일
You're welcome, but please Accept-click the answer to signify that it solved your problem.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by