How to make number that changes as name
1 回表示 (過去 30 日間)
古いコメントを表示
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/658635/Screenshot_20210619_183517.jpg)
0 件のコメント
回答 (1 件)
Abhinav Gupta
2021 年 6 月 20 日
編集済み: Abhinav Gupta
2021 年 6 月 20 日
Hi,
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
end
Its not recommended to name your variables dynamically. For more information, you could refer to the link below.
Hope this helps.
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!