How would I implement the following without eval in?

5 Ansichten (letzte 30 Tage)
Bruce Vernham
Bruce Vernham am 6 Dez. 2019
Kommentiert: Image Analyst am 7 Dez. 2019
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 Kommentare
Stephen23
Stephen23 am 6 Dez. 2019
Bearbeitet: Stephen23 am 6 Dez. 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 am 6 Dez. 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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 6 Dez. 2019
Despite the name, most of the methods apply to functions in general, not just graphics callback functions.
  2 Kommentare
Bruce Vernham
Bruce Vernham am 6 Dez. 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 am 7 Dez. 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?

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by