Why is my array definition ignoring all columns except the first?
Afficher commentaires plus anciens
I have created multiple arrays of 5 cells that each contain a 1200x3 double with the code below. (I know this isn't the best way to deal with a bunch of variables, but I just can't write out all 510 variables I have constantly within my time limit for this assignment)
for i = 1:5
E.Time{:,i} = RD.Empty_Time(:,i);
E.Toe{:,i} = [RD.Empty_Toe_X(:,i), RD.Empty_Toe_Y(:,i), RD.Empty_Toe_Z(:,i)];
E.Med_Ankle{:,i} = [RD.Empty_Med_Ankle_X(:,i), RD.Empty_Med_Ankle_Y(:,i), RD.Empty_Med_Ankle_Z(:,i)];
E.Lat_Ankle{:,i} = [RD.Empty_Lat_Ankle_X(:,i), RD.Empty_Lat_Ankle_Y(:,i), RD.Empty_Lat_Ankle_Z(:,i)];
E.Shank{:,i} = [RD.Empty_Shank_X(:,i), RD.Empty_Shank_Y(:,i), RD.Empty_Shank_Z(:,i)];
E.Med_Knee{:,i} = [RD.Empty_Med_Knee_X(:,i), RD.Empty_Med_Knee_Y(:,i), RD.Empty_Med_Knee_Z(:,i)];
E.Lat_Knee{:,i} = [RD.Empty_Lat_Knee_X(:,i), RD.Empty_Lat_Knee_Y(:,i), RD.Empty_Lat_Knee_Z(:,i)];
E.Hip{:,i} = [RD.Empty_Hip_X(:,i), RD.Empty_Hip_Y(:,i), RD.Empty_Hip_Z(:,i)];
end
example result: E.Toe = 1200x3 double 1200x3 double 1200x3 double 1200x3 double 1200x3 double
I then find all NAN entries from three variables that might potentially have them (all the others are complete) with the code below
for i = 1:5
E.Hgoodvals{:,i} = find(E.Hip{i}(:,1));
E.LKgoodvals{:,i} = find(E.Lat_Knee{i}(:,1));
E.MKgoodvals{:,i} = find(E.Med_Knee{i}(:,1));
E.goodvals{:,i} = intersect(E.Hgoodvals{:,i},E.LKgoodvals{:,i});
E.goodvals{:,i} = intersect(E.goodvals{:,i},E.MKgoodvals{:,i});
E.Time{:,i} = E.Time{:,i}(E.goodvals{:,i});
E.Index{:,i} = length(E.goodvals{:,i}); %Not relevant for this question
E.D_Time{:,i} = E.Time{:,i}(2:E.Index{:,i}) - E.Time{:,i}(1:E.Index{:,i}-1); %Not relevant for this question
end
The result from this relevant to this question is E.goodvals = 1007x1 double 941x1 double 956x1 double 903x1 double 967x1 double
I then try to create vectors of the necessary sections (eg from Toe to Ankle) and then only include the good values
for i = 1:5
E.Toe_Ankle{:,i} = [E.Toe{:,i}(:,1)-E.Lat_Ankle{:,i}(:,1), E.Toe{:,i}(:,2)-E.Lat_Ankle{:,i}(:,2), E.Toe{:,i}(:,3)-E.Lat_Ankle{:,i}(:,3)];
E.Toe_Ankle{:,i} = E.Toe_Ankle{:,i}(E.goodvals{:,i});
E.Ankle_Knee{:,i} = [E.Lat_Ankle{:,i}(:,1)-E.Lat_Knee{:,i}(:,1), E.Lat_Ankle{:,i}(:,2)-E.Lat_Knee{:,i}(:,2), E.Lat_Ankle{:,i}(:,3)-E.Lat_Knee{:,i}(:,3)];
E.Ankle_Knee{:,i} = E.Ankle_Knee{:,i}(E.goodvals{:,i});
E.Knee_Ankle{:,i} = [E.Lat_Knee{:,1}(:,1)-E.Lat_Ankle{:,i}(:,1), E.Lat_Knee{:,i}(:,2)-E.Lat_Ankle{:,i}(:,2), E.Lat_Knee{:,i}(:,3)-E.Lat_Ankle{:,i}(:,3)];
E.Knee_Ankle{:,i} = E.Knee_Ankle{:,i}(E.goodvals{:,i});
E.Hip_Knee{:,i} = [E.Hip{:,i}(:,1)-E.Lat_Knee{:,i}(:,1), E.Hip{:,i}(:,2)-E.Lat_Knee{:,i}(:,2), E.Hip{:,i}(:,3)-E.Lat_Knee{:,i}(:,3)];
E.Hip_Knee{:,i} = E.Hip_Knee{:,i}(E.goodvals{:,i});
end
Which I believe should create 4 different cell arrays each with 5 columns and each cell contains a different amount of rows by 3 column doubles. However the result from this is for example E.Toe_Ankle = 1007x1 double 941x1 double 956x1 double 903x1 double 967x1 double. And the column in all these doubles is just the first column (eg taking only E.Toe{:,i}(:,1)-E.Lat_Ankle{:,i}(:,1) and nothing after the comma).
I am trying to get for example E.Toe_Ankle = 1007x3 double 941x3 double 956x3 double 903x3 double 967x3 double
Is there something wrong with this that I am not seeing?
I can upload files if it is needed to see the actual data.
1 commentaire
Rather than nesting lots of identically-sized cell arrays inside one scalar structure, it looks like one non-scalar structure array would fit your data better:
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!