# Create an Matrix of Variables from a String input

22 views (last 30 days)
Surafel Taddesse on 18 Jul 2019
Answered: Mario Chiappelli on 19 Jul 2019
I'm not sure if I'm even asking the question the correct way, however, heres what I'm trying to accomplish,
I'm working on a Matlab Application:
I have an 8 x 10 matrix with a set of numbers. I also have an 8 x 10 matrix of variables A1 - H10. I've done this because I want the app to recall a digit everytime a variable is raised. The numbers in the matrix are results of compultations so they might vary case by case.
I want the user to be able to recall variables and graph them as needed.
x_var = [get(app.xvar,'value'),get(app.xvar2,'value'),get(app.xvar3,'value'),get(app.xvar4,'value')]
% These are just the numbers so they're easy enough to retrieve,
% As an example, one input was x_var = [2 4 6 8]
y_var = [get(app.yvar,'value'),get(app.yvar2,'value'),get(app.yvar3,'value'),get(app.yvar4,'value')]
% for this however I get an outcome like so y_var = 'A1D4G6H9'
% I wanted to get y_var = [A1,D4,G6,H9]
How can I fix my issue.
Any help is appriciated.
Jan on 19 Jul 2019
What does this mean: "8 x 10 matrix of variables A1 - H10"?
This is not clear to me also: "I want the app to recall a digit everytime a variable is raised"
Accessing the names of variables dynamically is a very bad idea. See TUTORIAL: Why and how to avoid Eval

Mario Chiappelli on 19 Jul 2019
I don't quite understand what you are asking, but if you problem is with getting the cells of the y_var to be separate instead of concatenated you can try the following:
y_var = string(4);
for i = 1:4
y_var(i) = get(app.yvar(i),'value')
end
You also need to stop writing variable names dynamically and instead store your values into arrays.
I changed your variable "yvar" to an array and the for loop will iterate through each element of "yvar".
This code is merely a skeleton of how you should be thinking of solving the problem. If you included more of your code, then we could have wrote more to help.