MATLAB Answers

0

filling array with data

Asked by Tobias Neumaier on 17 Aug 2019
Latest activity Edited by madhan ravi
on 17 Aug 2019
Hi,
stupid question I know.
But I always get the error message:
Index in position 1 is invalid. Array indices must be positive
integers or logical values.
Error in DAXKurs (line 30)
Abweichung(j,1) = log(Schlusskurs(i-1,1)/Schlusskurs(i,1));
This is my code:
for i = T:-1:1
for j = 1:T
Abweichung(j,1) = log(Schlusskurs(i-1,1)/Schlusskurs(i,1));
end
end
How can i fix the error?

  0 Comments

Sign in to comment.

Tags

1 Answer

madhan ravi
Answer by madhan ravi
on 17 Aug 2019
Edited by madhan ravi
on 17 Aug 2019

Abweichung=nan(size(Schlusskurs(:,1)));
ii = T:-1:2;
for k = 1:numel(ii)
Abweichung(k) = log(Schlusskurs(ii(k)-1,1)/Schlusskurs(ii(k),1));
end
Abweichung(isnan(Abweichung))=[]
Ohne Schleife kann man auch den gleichen Kode erstellen.
Abweichung=log(Schlusskurs(ii-1,1)./Schlusskurs(ii,1))
% wenn du nicht die heutige Version benutzt < 2016b, dann
Abweichung=log(bsxfun(@rdivide,Schlusskurs(ii-1,1),Schlusskurs(ii,1)))

  0 Comments

Sign in to comment.