필터 지우기
필터 지우기

How to store vector in column matrix?

조회 수: 5 (최근 30일)
Phil Whitfield
Phil Whitfield 2018년 5월 13일
댓글: Phil Whitfield 2018년 5월 13일
So here is my for loop:
for i=1:1000
x=randfixedsum(5,1,1,0,1);
ret= x(1)*Returns(:,1) +x(2)*Returns(:,2) +x(3)*Returns(:,3) +x(4)*Returns(:,4) +x(5)*Returns(:,5);
am=mean(ret)*251;
as=std(ret)*sqrt(251);
hold all
plot(as,am,'r.')
end
x is a 1x5 matrix that changes each loop, I am looking to store the values of each loop in a matrix so I know what values were used on each loop.
I tried adding in a
y=[x(i);x(i+1)];
But that just gave an error. Any help would be great thanks

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 5월 13일
Outside for loop define
y = zeros(1000, 5);
and then inside for loop use
x=randfixedsum(5,1,1,0,1);
y(i, :) = x;
all the values will be stored in y.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by