How Can I Assign variable Name?

90 ビュー (過去 30 日間)
Giorgi
Giorgi 2015 年 1 月 14 日
編集済み: Stephen23 2019 年 6 月 25 日
Hi guys, I have some kinds of a data, that is in the variable called as First, and each day I have to update that data, but I should not lost the last data with respective variable name, so when I update data I have to create new variable for this updated data. well it is easy when you are making it manually, but in my case it should create automatically and the name of new variables should be the date of updated day for example today is 1/14/2015 so if i updated today variable name should be 1/14/2015. Any ideas would be a great job for me.
  1 件のコメント
d p
d p 2016 年 7 月 6 日
Great answer!

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

採用された回答

Stephen23
Stephen23 2016 年 7 月 7 日
編集済み: Stephen23 2019 年 6 月 25 日

その他の回答 (2 件)

Shoaibur Rahman
Shoaibur Rahman 2015 年 1 月 14 日
x = 1:5;
eval([datestr(date,'mmmm_dd_yyyy') '= x']);
x is stored in a new variable named based on today's date. If you run the above code today, then you will get:
January_14_2015 =
1 2 3 4 5
  1 件のコメント
Iain
Iain 2015 年 1 月 14 日
This tells you, roughly, how to do it. HOWEVER, DON'T do it that way. It is a BAD idea.
Do it this way instead
days_data{day_of_month,month_of_year,year_from_x} = y;
That will give you a cell array that is 31 x 12 x number of years where each element can be as much data as you need.

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


Yona
Yona 2015 年 1 月 14 日
編集済み: Yona 2015 年 1 月 14 日
you can use eval function.but it not recommended. and you cannot use / in variable name and it cannot start with a number.
so call it d01142015 or something like this.
X=['tr' num2str(14)];
eval(X, 'sin(pi/2)')
another way is to create a cell matrix. the first column will contain the date and the second column will contain all the data for the day.

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by