How Can I Assign variable Name?

201 views (last 30 days)
Giorgi on 14 Jan 2015
Edited: Stephen23 on 25 Jun 2019
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.

Accepted Answer

Stephen23 on 7 Jul 2016
Edited: Stephen23 on 25 Jun 2019

More Answers (2)

Shoaibur Rahman
Shoaibur Rahman on 14 Jan 2015
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 Comment
Iain on 14 Jan 2015
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.

Sign in to comment.

Yona on 14 Jan 2015
Edited: Yona on 14 Jan 2015
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.


Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!