Workspace variable not available despite visibility in another variable
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
VBBV
2024 年 7 月 30 日
編集済み: VBBV
2024 年 7 月 30 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!