Create an Matrix of Variables from a String input
조회 수: 8 (최근 30일)
이전 댓글 표시
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.
댓글 수: 1
Jan
2019년 7월 19일
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
답변 (1개)
Mario Chiappelli
2019년 7월 19일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!