I have two fairly basic questions about pulling values from vectors.
n=0:40;
i=n+1
income(i) = initial_income*(1+inflation).^(n)
income(1)
My goal is to pull the second vector from the list while using 1 as the indicator. I'm working in terms of years and income(1) doesn't justify the first year. It amounts to the initial value. I need income(1) to be what currently is income(2) and income(2) to be income(3) so on so forth. How can I manage to do this?
Here's my second question. I know income(1) pulls the first value, but what does income(i) imply? I'm under the assumption that it needs to be used here, but I also want to make sure I understand the reasons why I would use it.
Let me know if anymore information is needed. Thanks!

 채택된 답변

Matt J
Matt J 2021년 3월 12일
편집: Matt J 2021년 3월 12일

0 개 추천

but what does income(i) imply? I'm under the assumption that it needs to be used here
Nope. It doesn't:
income = initial_income*(1+inflation).^(1:40);

댓글 수: 3

But how about in the case that I want i = n+1 so that income(1) actually pulls the value of income(2)?
So like:
income(i) = income(n+1)
% therefore income(1) is no longer the first value but the second value.
Sorry if this doesn't make sense.
Matt J
Matt J 2021년 3월 12일
편집: Matt J 2021년 3월 12일
You mean you want to start with a vector income and then have the values stored in the vector shift locations? There are a number of different ways to do that, depening on what you intend for the final value:
income=randi(100,1,5) %example
income = 1×5
15 74 77 9 90
incomeShifted=income(2:end) %truncated shift
incomeShifted = 1×4
74 77 9 90
incomeShifted=circshift(income,-1) %circulant shift
incomeShifted = 1×5
74 77 9 90 15
incomeShifted=[income(2:end) , 0] %padded shift
incomeShifted = 1×5
74 77 9 90 0
Nathan Brannan
Nathan Brannan 2021년 3월 13일
That's exactly what I was looking for!
Thank you!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2021년 3월 12일

댓글:

2021년 3월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by