Dot indexing does not support negative variables in a loop - how to solve?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all.
I have data of dimensions 1436213x11. Cropped data set attached ('data').
The data has a structure as depcited below. The structure is the same for each frame (11 k of frames).
My objective is to extract the variables in the black rectangle and structure them in a table (each variabale in a column). As below.
I do this as presented below.
load 'Data';
%% get data for left foot
idx_lfoot_start = find(strcmp(data_raw1(:, 2), '"HX210.11.31.M7-LF S0021"'));
idx_lfoot_end = find(strcmp(data_raw1(:, 2), '"HX210.11.31.M7-RF S0021"'));
% indices between idx_lfoot_start and idx_lfoot_end
idx = arrayfun(@(idxStart, idxEnd) idxStart:idxEnd, idx_lfoot_start, idx_lfoot_end,...
'UniformOutput', false);
% corresponding values for variables of interest
c.l_avgP = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'Average Pressure (kPa)')), 2), idx);
d.l_minP = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'Minimum Pressure (kPa)')), 2), idx);
e.l_peakP = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'Peak Pressure (kPa)')), 2), idx);
f.l_contactArea = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'Contact Area (cm²)')), 2), idx);
g.l_totalArea = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'Total Area (cm²)')), 2), idx);
h.l_contactPerc = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'Contact %')), 2), idx);
i.l_load = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'Est. Load (N)')), 2), idx);
j.l_cop_row = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'COP Row')), 2), idx);
k.l_cop_column = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'COP Column')), 2), idx);
l.l_imu_qx = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'IMU QX')), 2), idx);
m.l_imu_qy = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'IMU QY')), 2), idx);
n.l_imu_qz = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'IMU QZ')), 2), idx);
o.l_imu_qw = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'IMU QW')), 2), idx);
p.l_imu_ax = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'IMU AX')), 2), idx);
r.l_imu_ay = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'IMU AY')), 2), idx);
s.l_imu_az = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'IMU AZ')), 2), idx);
t.l_imu_gx = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'IMU GX')), 2), idx);
u.l_imu_gy = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'IMU GY')), 2), idx);
w.l_imu_gz = cellfun(@(idxx) data_raw1(idxx(strcmp(data_raw1(idxx, 1), ...
'IMU GZ')), 2), idx, 'UniformOutput', false);
%% save in table each variable
T_avgP = struct2table(c);
T_minP = struct2table(d);
T_peakP = struct2table(e);
T_conArea = struct2table(f);
T_totalArea = struct2table(g);
T_contactPerc = struct2table(h);
T_load = struct2table(i);
T_cop_row = struct2table(j);
T_cop_column = struct2table(k);
T_imu_qx = struct2table(l);
T_imu_qy = struct2table(m);
T_imu_qz = struct2table(n);
T_imu_qw = struct2table(o);
T_imu_ax = struct2table(p);
T_imu_ay = struct2table(r);
T_imu_az = struct2table(s);
T_imu_gx = struct2table(t);
T_imu_gy = struct2table(u);
T_imu_gz = struct2table(w);
%% combine each table into one table
T_LeftFoot = [T_avgP, T_minP, T_peakP, T_conArea, T_totalArea, T_contactPerc, T_load, T_cop_row, T_cop_column, ...
T_imu_qx, T_imu_qy, T_imu_qz, T_imu_qw, T_imu_ax, T_imu_ay, T_imu_az, T_imu_gx, T_imu_gy, T_imu_gz ];
The code works fine as it is. However, beacuse I have multiple datasets in a folder I am using a loop (to run through each data file). When I run the code using a loop I get the error: Unable to perform assignment because dot indexing is not supported for variables of this type. Some of the variables in the red rectangle (first picture) are negative which seems to be the problem.
How can I solve this please?
3 commentaires
Walter Roberson
le 3 Nov 2021
Might I suggest that you convert data_raw(:,2) into a table in which you use data_raw(:,1) as RowNames ? Then you could get rid of all that strcmp() indexing and just use, for example,
T{Peak Pressure (kPa)', 1}
Réponse acceptée
Cris LaPierre
le 4 Nov 2021
It looks like you may already be using n as a variable elsewhere in your code, so you probably need to clear it before trying to use it to create a structure.
% works
m=5;
clear m
m.a = 6;
% your error
n = 5;
n.a = 6;
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!