Searching structure that has all caps field names with list that varies in case.

9 Ansichten (letzte 30 Tage)
Hello,
I am comparing two separate files of data and have loaded the .mat files into structs. One file has field names that are in all capital letters. Ideally I just want to ignore the case altogether. Hpwever, I am unsure how to do this and so I have tried using:
x = upper(load('filename.mat'))
%and
x= load('filename.mat')
y=upper(x)
To change all the fields to uppercase. Niether of these work. ( I also changed the search variables to match case for this)
My code looks like this:
myVars = {'Abc_B', 'Aaa_A', 'B_Ahh', 'Ba_Bcc', 'Dea_C_CC' };
b_struct = load('filename1.mat'); %all upper case
f_struct = load('filename2.mat'); %variable case
for iVar=1:numel(myVars)
f_sp = f_struct.(myVars{iVar});
b_sp = b_struct.dArray.(myVars{iVar});
...
end
And the issue happens when b_struct tries to read in 'B_Ahh', because b_struct the field is 'B_AHH'
The error that matlab gives is this:
Reference to non-existent field 'B_Ahh'.
Error in final_dataPrep
b_sp = b_struct.dArray.(myVars{iVar});
But it outputs previous fields whose case match my search words.
Ideally, I just want to ignore the case altogether.
I am lost and frustrated about this. Any guidance would be greatly appreciated!

Antworten (1)

Fangjun Jiang
Fangjun Jiang am 23 Feb. 2021
Bearbeitet: Fangjun Jiang am 23 Feb. 2021
for iVar=1:numel(myVars)
b_sp = b_struct.dArray.(upper(myVars{iVar}));
end
  3 Kommentare
Fangjun Jiang
Fangjun Jiang am 23 Feb. 2021
Try this and figure it out
%%
clear b_struct
b_struct.dArray.B_AHH=1;
myVars{1}='B_Ahh';
b_struct.dArray.(upper(myVars{1})) % this works
b_struct.dArray.(myVars{1}) % this has error
ans =
1
Reference to non-existent field 'B_Ahh'.
Error in Untitled (line 7)
b_struct.dArray.(myVars{1})
Georgia Kennedy
Georgia Kennedy am 23 Feb. 2021
Ok, thank you for taking the time to answer and the guidance!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu File Operations 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!

Translated by