Workspace variable not available despite visibility in another variable
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi Together,
I have the problem that some signals disappear in workspace, when some signals of measurement files are renamded to variables, which I use in MATLAB code.
Here is the code:
if(exist('Testsignal_1','var'))
Current=Testsignal_1;
end
keepvars(end+1) = {'Current'};
After Run the variable Current and Testsignal_1 disappear. But in variable keepvars the signal Current is still avaible.
Furthermore I do this for other signals and for them, the variables are avaible in the workspace.
Signals and variables only occur once in the script.
I got also no failure in Command Window.
Do you have an idea, why have only for two signals this problem?
0 Kommentare
Akzeptierte Antwort
VBBV
am 30 Jul. 2024
Bearbeitet: VBBV
am 30 Jul. 2024
if you want to store the variable names Testsignal_1 and Current then you need to use an indexing variable as below. If this code snippet is present in a bigger code structure which is repeated several times, then the index helps to store the variable names and signals for each run/ iteration. In your code, the name of the signal and variables are not character vectors but defined by a value.
If the if-end condition is not satisfied, then the signal and variable names will NOT appear in workspace. The below code will store both signal and variable names and would appear in workspace if the condition is satisfied.
k = 1; % iterator index
if(exist('Testsignal_1','var'))
Current{k}='Testsignal_1'; % signal name as character vector stored in cell array
k = k+1; % increment
end
keepvars(end+1) = Current; % store or assign the cell array to keepvars data array present in bigger code structure
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!