Effacer les filtres
Effacer les filtres

How Can I Assign variable Name?

53 vues (au cours des 30 derniers jours)
Giorgi
Giorgi le 14 Jan 2015
Modifié(e) : Stephen23 le 25 Juin 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.
  1 commentaire
d p
d p le 6 Juil 2016
Great answer!

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 7 Juil 2016
Modifié(e) : Stephen23 le 25 Juin 2019

Plus de réponses (2)

Shoaibur Rahman
Shoaibur Rahman le 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 commentaire
Iain
Iain le 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.

Connectez-vous pour commenter.


Yona
Yona le 14 Jan 2015
Modifié(e) : Yona le 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.

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by