MATLAB Answers

How to make number that changes as name

조회 수: 2(최근 30일)
Dilovan  Rafeeq
Dilovan Rafeeq 2021년 6월 19일
댓글: Dilovan Rafeeq 2021년 6월 21일
For example I have yi I want to make the I changes by using loops but at the same time I don't want to make it disturb the original equation like (4y_(i-1)) +(6y_(i+6)) I want it to solve part of this


Abhinav Gupta
Abhinav Gupta 2021년 6월 20일
편집: Abhinav Gupta 2021년 6월 20일
You can use cell array for this. Instead of creating a new variables every time in a loop, you could index those in a single cell array. That means, now instead of referring to y_i, you should refer this as y{i}. Your original equations should remain undisturbed.
eg. (4y{i-1}) +(6y{i+6}).
Example code.
N = 10;
y = cell(1,N);
for k = 1:N
y{k} = k*k; % do your changes accordingly
Its not recommended to name your variables dynamically. For more information, you could refer to the link below.
Hope this helps.
  댓글 수: 1
Dilovan  Rafeeq
Dilovan Rafeeq 2021년 6월 21일
It's really brilliant idea but pardon me I'm still beginner in matlab how can I make that with my program I mean I have name and numbers shifting based on the loop for example whne I = 1 you can see the numbers and names as it is but when i=2 the numbers with constant and number of contacts shift by 1

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

Community Treasure Hunt

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

Start Hunting!

Translated by