How Can I Assign variable Name?

조회 수: 43 (최근 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.

채택된 답변

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 CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by