When checking to see if a variable has been created within a struct, "exist" and "isfield" both come back 0 when the struct variable exists and is populated.
Show older comments
I'm using an EEGLab function to clean some data. If it determines a row has a significant amount of noise and should be removed, it creates a new variable in the stuct. If no rows are removed, this variable is not created.
The code is set up to check for which, if any rows have been removed by the cleaning function.
I've tried using both the exist() and isfield() functions, both return logical 0, but when I open the struct from the Workspace, it clearly shows that variable in the struct and populated with data.
I've tried both isfield('EEG_temp','etc.clean_channel_mask') and isafield('EEG_temp.etc','clean_channel_mask') but receive the same results. (code and results below, also a screen grab showing that EEG_temp struct does include the populated variable.)
If done manually, bypassing the "if" statement and using exists or isfield directly, even when they boht return logical 0, the ch_bad loads the correct data.
Any suggestions on how to get this working correctly? Thank you.
EEG_test = clean_rawdata(EEG, flatline, hpf_data, corr_threshold, linenoise, repair_busrsts_std, remove_timewindows);
if exist('EEG_temp.etc.clean_channel_mask','var') % Load the clean_channel_mask from the EEG struct
ch_bad = EEG_test.etc.clean_channel_mask; % copy that mask to ch_bad (0 = bad channel)
Both exist and isafield return
isfield('EEG_temp','etc.clean_channel_mask')
ans =
logical
0

1 Comment
dpb
on 8 Oct 2022
No data attached with which to try anything ...
Accepted Answer
More Answers (0)
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!