필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

If statement in a for loop

조회 수: 2 (최근 30일)
Christoffer Benneballe
Christoffer Benneballe 2019년 12월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi MathWorks
I have a simple loop, where I test in this small sample for 1:4 time periods. If the statement is true, then I would like to print 12 of the returns at a time from RI_vec to retSizeValue1. It is because the if statement is testing an argument based on an annual value, and if it is true I'd like to collect monthly returns for the following year.
The statement is only done for the first 12 observations.
I've tried adjusting line 82, where the task is to be performed, by writing (i(+12),j) but that does not work. This would just result in the statement being performed for observation 13:24.
I've attached the data, the code and a screenshot below.
All the best,
Christoffer
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 12월 25일
Christoffer Benneballe
Christoffer Benneballe 2019년 12월 25일
Hi Walter
Thank you for commenting with a suggesting. Do you mean i+(0:11) both in the vector to be filled - retSizeValue1 - and in the vector - ret_vec - from where the values are drawn?
I've tried to fill it out in that way, but the result is that the first 15 rows are filled - not the full 36 rows.
Did I interpret the suggestion correct?
Best wishes,
ChristofferUdklip.PNG

답변 (1개)

Image Analyst
Image Analyst 2019년 12월 24일
Try to find an algorithm that gives you the starting and stopping indexes, then to print, use
fprintf('%f, ', RI_vec(index1:index2, j));
  댓글 수: 1
Christoffer Benneballe
Christoffer Benneballe 2019년 12월 25일
Hi Image Analyst
Thank you for your quick response.
The issue is not really to print the RI_vec, but that I do not now how to adjust the loop, such that it will take the first 1:12 rows from RI_vec, store them in the 1:12 rows of the retSizeValue1, do the same for the next 13:24 rows and again for the last 25:36 rows.
Do you know what should be adjusted?
All the best,
Christoffer

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by