How would I implement the following without eval in?

4 views (last 30 days)
This is in a for loop with signalist being a list of variabeles in the workspace I wish to evaluate.
signalvalue = evalin('base', [signallist{i}]);
  4 Comments
Stephen23
Stephen23 on 6 Dec 2019
Edited: Stephen23 on 6 Dec 2019
"How do I assign values from worspace values to be evaluated in a for loop?"
Experienced MATLAB users would simply pass the data as an output argument. Note that the question as you posed it is not answerable, as you did not explain anything about the context of that code: depending on where that code is used, there can be very different, but neat and efficient methods to pass it into the base workspace.
You can find methods to pass data betwen callback functions here:
"I want to assign "signalvalue" the contents of each variable one at a time in a for loop."
Bruce Vernham
Bruce Vernham on 6 Dec 2019
I am calling s function which outputs it's rests to the workspace. The workspace names will vary depending on which ones are desired but one does not want to save the whole workspace just the desired variables and the variable length may be different so the need to be trimmed to be the same for later usage

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 6 Dec 2019
Despite the name, most of the methods apply to functions in general, not just graphics callback functions.
  2 Comments
Bruce Vernham
Bruce Vernham on 6 Dec 2019
I am not assigning the variable names dynamically. They have already be assigend.
I need to manipulate the variable contents to clean and shorten the data.
Image Analyst
Image Analyst on 7 Dec 2019
If they've already been assigned then presumably you know their names and you can use those names in your code.
Disaster scenario follows:
If your variables are assigned dynamically and you have no idea what they're named (like some arbitrary, random program was run and loaded some variables into the base workspace and you have no knowledge of what they might be called because you don't know what program was run - a bad idea) then you'll have to get the names of the variables and get them into your program. But once you have them in your program's workspace, how will you USE them because the code after that point won't know the variables' names. (It's possible but we don't want ot encourage such coding). For example, let's say program1 puts var1 into the base workspace, and program2 puts var2 into the base workspace. Now let's say you have no idea which program had been run and you come along and you run a "program3.m" and for some reason it might need to get var1 and use it, or get var2 and use it. Let's say you wanted to assign it to var3. Well, if you don't know the name of the variable to retrieve from the base workspace (var1 or var2), would you do
var3 = var1;
or
var3 = var2;
Even if you knew it was either var1 or var2, you should know name var1 or var2. It wouldn't be a variable with some totally unknown name. If you had no idea and went to look in the base workspace and found, say 20 variables with various names in there, how on earth would you know which to get and stuff into var3?

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!