Filter löschen
Filter löschen

Why is this function returning the wrong size matrix

1 Ansicht (letzte 30 Tage)
Ali
Ali am 30 Mär. 2013
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 Kommentar
Cedric
Cedric am 30 Mär. 2013
Bearbeitet: Cedric am 30 Mär. 2013
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by