Data Structure Reference Assignment
3 次查看(过去 30 天)
显示 更早的评论
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
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!