Extract specific field names and associated data from a structure
21 views (last 30 days)
here is a screenshot of my structure I created using following code:
file = 'myfile';
struct = dir (fullfile (file, '*.xlsx'));
for i = 1:numel (struct);
F = fullfile (file, struct(i).name);
[struct(i).num, struct(i).txt, struct(i).raw] = xlsread (F); % insert .num, .txt. and .raw into the structure
Attached you find the data for one .xlsx file. It is possible for me to extract the fields seperaly using:
x = struct(1).num (8:14, 3:end); % extract position 1 field .num; extract only row 8.14 and column 3:end
Know I want to extract all positions with 'bf_s' simultaniously using a if statement to analyse the data for each condition seperatly to calculate single and mean values.
Thank you for your support!
Stephen23 on 23 Aug 2021
Edited: Stephen23 on 23 Aug 2021
Rather than using an IF it would be simpler to specify an appropriate filename for DIR:
P = 'myfile';
S = dir(fullfile(P,'*bf_s.xlsx')); % specify BF_S here
for k = 1:numel(S);
F = fullfile(P,S(k).name);
[S(k).num, S(k).txt, S(k).raw] = xlsread(F);
S(k).ext = S(k).num(8:14,3:end);
You can loop over S or use the methods shown here:
Is there a particular reason why you want to use XLSREAD and not READMATRIX/READTABLE ?