フィルターのクリア

How to get data from variables that change the name?

4 ビュー (過去 30 日間)
Kelly Kyriakou
Kelly Kyriakou 2017 年 1 月 13 日
コメント済み: Image Analyst 2017 年 1 月 14 日
I have the variables day1,day2,day3....day15. I want to get the data of each variable within a loop. How I can do it?
Thank you in advance
  2 件のコメント
Stephen23
Stephen23 2017 年 1 月 13 日
編集済み: Stephen23 2017 年 1 月 13 日
@Kelly Kyriakou: read this carefully:
Learn to use indexing rather than make lots of separate variables. Then your life suddenly gets better :)
Kelly Kyriakou
Kelly Kyriakou 2017 年 1 月 13 日
Thank you very much. Indeed being a beginner at matlab the idea of indexing is not well-established in my mind.

サインインしてコメントする。

回答 (2 件)

John Chilleri
John Chilleri 2017 年 1 月 13 日
Hello,
A simple solution would be:
Days = [day1 day2 day3 ... day15];
Then call Days(:,i) for the ith days data if it's a vector (assuming column vectors), or just Days(i) if it's a scalar.
Hope this helps!

Image Analyst
Image Analyst 2017 年 1 月 13 日
The "data of each variable" and the variable itself are one and the same thing. Just assign it to another variable if you want, or just start using it.
someOtherVariable = day1;
someOtherVariable2 = day2 * pi * log(42);
someOtherVariable3 = day5 * cos(day12) + day9;
result = SomeFunction(day7);
and so on. You don't need to do anything special to the variable to access it's "data". The variable and its data are the very same thing.
  2 件のコメント
Kelly Kyriakou
Kelly Kyriakou 2017 年 1 月 13 日
Actually, I have many loops to do it manually. I would prefere to use it like "day%d" where the d = 1:15.
Image Analyst
Image Analyst 2017 年 1 月 14 日

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by