Data Structure Reference Assignment

3 次查看(过去 30 天)
Ruud
Ruud 2021-9-8
评论: Ruud 2021-9-9
When I implement the below it works fine for a single array variable:
Le2=length(GC);
FzGC2=nan(1000,Le2);%consider how to adjust ground contact lengths for different vector lengths during further eval
%Collect last step
for i=1:Le2 %or use N value
if ~isnan(GC(i,2))
tempFz2 = Fz(GC(i,1):GC(i,2)); %gets ground contact Fz data
length_tempFz2 = size(tempFz2,1); %find length of ground contact Fz data
FzGC2(1:length_tempFz2,i)= Fz(GC(i,1):GC(i,2)); %adjusts size of array to store it in
else
tempFz2 = Fz(GC(i,1):end); %gets ground contact Fz data
length_tempFz2 = size(tempFz2,1); %find length of ground contact Fz data
FzGC2(1:length_tempFz2,i)= Fz(GC(i,1):end); %adjusts size of array to store it in
end
end
However when I create a struture and try to do the same kind of reference I am getting an 'Index exceeds matrix dimensions' errror on the first bolded line and then the second bolded line if I remove the first while troubleshooting. GC is a 170*2 array with references ranging from 700 to 12000. Both Fz and CoPx are similar sizes - 1 structure with 6 fields (Trials 1-6). Trial sizes within the structure are 30000 or 120000 * 1
for q=1:length(filenames)
Q = size(CoPx.(fnc{q}),1);
%CoPx.(fnc{q})(isnan(fnc{q}))= 0;
for i=1:length(GC)
if ~isnan(GC(i,2))
tempCoPx = CoPx.(fnc{q})(GC(i,1):GC(i,2)); %gets ground contact
length_tempCoPx = size(tempCoPx,1); %find length of ground contact
CoPxGC(1:length_tempCoPx,i)= CoPx.(fnc{q})(GC(i,1):GC(i,2)); %adjusts size of array to store it in
else
tempCoPx = CoPx.(fnc{q})(GC(i,1):end); %gets ground contact Fz data
length_tempCoPx = size(tempCoPx,1); %find length of ground contact Fz data
CoPxGC(1:length_tempCoPx,i)= CoPx.(fnc{q})(GC(i,1):end); %adjusts size of array to store it in
end
CMean = mean(CoPxGC);
A=mean(CMean(1:2:end));%odd number contacts
B=mean(CMean(2:2:end));%even number contacts
%assuming +X is to the right
if A > B
RIGHT=1;
LEFT=2;
else
LEFT=1;
RIGHT=2;
end
end
%assign [left TD, left TO, right TD, right TO]
end
Can you please assist?
  5 个评论
Jan
Jan 2021-9-9
CoPx.(strcat('Trial_',num2str(q)))
This is hiding the index of an array in the field name. Use arrays with inidices is easier than this indirection.
This looks complicated: Fz.(fn{q})(n:L) < threshold . You can move it out of the loop:
hasFz = (Fz.(fn{q})(n:L) >= threshold);
Now the change point can be found by:
padFz = [false, hasFz, false];
touchDown = strfind(padFz, [false, true]);
liftOff = strfind(padFz, [true, false]);
By this way, you do not need a loop.
Ruud
Ruud 2021-9-9
As per suggestions yesterday I've changed all references with .fn{q} to a single letter for easier troubleshooting. I now have:
F = Fz.(fn{q});
X = CoPx.(fnc{q});
CoPxGC now is represented by a 482*170*6 array and CMean 482*1*6 from the code previoulsy shared albeit I am optimzing/simplifying it as we speak. What I realize though is that GC is bascially only holding the last set of values for the iteration so this will have a domino effect on the CoPxGC or FzGC values since it will not have data to reference obvioulsy for the specific trial it is meant to. When I modify GC to GC(N,2,q) it outouts a blank matrix. Forgive me I have minimal experience with dealing with 3D arrays so am learning as I research, modify and test.
Also, I am a bit unclear by the change point suggestion. I substiute to get the below but get a whole different output in CoPxGC and in all scenarios I only get a 2D array for FzGC when adding time normalization.
GC=nan(1000,2); %ground contacts [TD, TO]
while n<L
if C %foot is in contact, look for toe-off
n = find(hasFz,1,'first')+n-1;
if isempty(n) %cannot find any more
n=L; %leave while loop
else
GC(N,2)=n;
C=false; %now foot is not in contact
N=N+1;
end
else %look for touchdown
n=find(hasFz,1,'first')+n-1;
if isempty(n) %cannot find any more
n=L; %leave while loop
else
GC(N,1)=n;
C=true; %now foot is in contact
end
end
end
end
FzGC with time normalization (below returns an index exceeds matrix dimensions when done in this way)
for i = 1:Le %or use N value
if isnan(GC(i,2))
cFz = Fz(GC(i,1):end);
else
cFz = Fz(GC(i,1):GC(i,2));
end
FzGC2(1:numel(cFz, i)) = cFz; % adjusts size of array to store it in
FzGC2(:,i,j)=timenorm(cFz,1001)
%Time Normalization Function:
function [ output ] = timenorm( data,numsteps)
%frames=(100/step_size)+1;
t0=1:length(data);
t1=linspace(1,length(data),numsteps); %0 to 100% on 0.1% increments i.e calculate what frames are needed if we only have 1001 frames
output=interp1(t0,data(t0),t1,'spline'); %using frames t0 and Force data interpolate to t1
end

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

产品


版本

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by