I have a question regarding this type of code:
First = ["A","B","C"];
Second = ["D","E","F"];
Group = ["First", "Second"];
for gr = Group
current = gr;
for number = 1:numel(current)
my_variable(number) = current(number);
end
end
That's the reproduction of my problem. In this case my_variable is equal to "First" for example. But I wanted it to be "A" then "B" then "C" from variable named "First".
For my understanding this code should do the following:
- 1st step:
for gr = Groupmeans gr = First to Second - 2nd step:
current = gr;means current = First - 3rd step:
for number = 1:numel(current)means number = 1:3 (number of elements in "First") - 4th step:
my_variable(number) = current(number);means my_variable = First(1) = "A"
Instead of that I get my variable equal to "First" or "Second".
I hope you understand what I mean.
P.S. the string arrays I'm using with double quotes (" ") like First = ["A","B","C"]; are only available in Matlab 2016b or later.
numel(current) = numel('First') = 5as in there are 5 elements in the stringFirst. You could donumel(eval(current))which would evaluate the variable from the string, but please don't - usingevalis bad practice, especially when easily avoidable like here. Instead try using structs or cell arraysmy_variablewith the values inSecond, and those extracted fromFirstare lost...