Use inputdlg to recall variables based on name

3 views (last 30 days)
I have a matlab file that uses an inputdlg to build matrices based on individual data points and performs systems of equations solving. I am trying to find a way to recall stored matricies based on their assigned name in the workspace. My current process involves an inputdlg which prompts for input of the individual elements of each matrix (since each column represents a different type of data measure) and then builds the matrix from there. However, since the matrices I am concerned with do not change, I would like to be able to store these matrices (likely in a different file within the same folder) and then run an inputdlg which could recognize that the character input is referencing a stored matrix. For example, If I had sample1=[5 7 4 8], sample2=[5 0 6 1] and sample3=[8 9 2 9], I am trying to find a way to select the third matrix by typing in "sample3" in a single-input inputdlg.
Thank you for any help you can provide
  1 Comment
Stephen23
Stephen23 on 15 Jan 2019
Edited: Stephen23 on 15 Jan 2019
"I am trying to find a way to recall stored matricies based on their assigned name in the workspace."
Dynamically accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know why:
Much simpler would be to use indexing (very efficient), or the fields of a structure:

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 14 Jan 2019
Edited: Walter Roberson on 14 Jan 2019
Store them as fields of a struct. Or use the names as keys of a containers.Map .
Also consider building a uicontrol('style', 'list') or 'style', 'popup' with the available names, in combination with one of the two above techniques or in combination with indexing a cell array.

Categories

Find more on Structures in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!