필터 지우기
필터 지우기

Why is this function returning the wrong size matrix

조회 수: 1 (최근 30일)
Ali
Ali 2013년 3월 30일
I wrote a very simple function to calculate stock price return regardless of the number of companies listed in the array. The company stock prices are listed in separate columns. The function code is:
function percentReturn=retCalc(prices)
percentReturn=prices(1:end-1,:)./prices(2:end,:)-1;
I would assume that this function should calculate the return regardless of the number of columns in the matrix. However, it just returns the first column of return. Can someone please tell me what I'm doing wrong?
  댓글 수: 1
Cedric
Cedric 2013년 3월 30일
편집: Cedric 2013년 3월 30일
Did you check that the local variable prices has really the correct size? If you add the line
size(prices)
right before the line computing percentReturn, you might see that prices doesn't have as many columns (companies) as what you think. Well, reading again your statement .. the way you perform your computation suggests that there is one company per column, and therefore that prices vary along rows, which is not what you seem to indicate above.

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by