How to name a variable?
Show older comments
This question maybe silly,I am new to matlab. I have two variables, lets say a and b, I want to create a new variable which's value is a_b; how can I do it?
Answers (2)
Azzi Abdelmalek
on 15 Jun 2016
Edited: Azzi Abdelmalek
on 15 Jun 2016
0 votes
Read this http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
I don't know what is your aim by doing this, but it seems it's a bad idea
Star Strider
on 15 Jun 2016
Just call it ‘a_b’.
For example:
a_b = a + b;
As a general rule, it is best to use numeric or cell arrays to name what might be best considered to be elements of arrays (so ‘c(k)’ or ‘c{k}’ is the correct way to create a new variable as part of an array, and ‘c_k’ is quite definitely not the correct way), variables are best named to be as descriptive as possible.
For example:
mean_a_b = mean(a.*b);
is better than:
a_b = mean(a.*b);
Categories
Find more on Matrix Indexing 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!