Why command window outputs 10 times ans = logical 1? See my separate comment, too

2 次查看(过去 30 天)
I cannot find where am I missing the semicolon in the following code:
for j = 2:3
for t= 1:10
if j ==2 % Stairs up
for tt=1:2
if length(gait_events{j}{1,t})==3 && length(gait_events{j}{5,t})==3 && strcmp(side,'Left') % Left leg analyzed, starts with Left Leg
switch tt
case 1
idx_50TT{j}(t,tt)= round((gait_events{j}{3,t}(1,1) + gait_events{j}{7,t}(1,1))/2*fs);
case 2
idx_50TT{j}(t,tt)= round((gait_events{j}{3,t}(end,1) + gait_events{j}{2,t}(end,1))/2*fs);
end
elseif length(gait_events{j}{1,t})==3 && length(gait_events{j}{5,t})==3 && strcmp(side,'Right') % Right leg analyzed, starts with Right Leg
switch tt
case 1
idx_50TT{j}(t,tt)= round((gait_events{j}{3,t}(1,1) + gait_events{j}{7,t}(1,1))/2*fs);
case 2
idx_50TT{j}(t,tt)= round((gait_events{j}{7,t}(end,1) + gait_events{j}{6,t}(end,1))/2*fs);
end
else
disp('Not a LL or RR subject');
end
end
else j==3 % Stairs down
for tt=1:2
if length(gait_events{j}{1,t})==3 && length(gait_events{j}{5,t})==3 && strcmp(side,'Left') %Left leg analyzed, starts with Left Leg
switch tt
case 1
idx_50TT{j}(t,tt)= round((gait_events{j}{8,t}(1,1) + gait_events{j}{5,t}(1,1))/2*fs);
case 2
idx_50TT{j}(t,tt)= round((gait_events{j}{3,t}(2,1) + gait_events{j}{1,t}(end,1))/2*fs);
end
elseif length(gait_events{j}{1,t})==3 && length(gait_events{j}{5,t})==3 && strcmp(side,'Right') % Right leg analyzed, starts with Right Leg
switch tt
case 1
idx_50TT{j}(t,tt)= round((gait_events{j}{4,t}(1,1) + gait_events{j}{1,t}(1,1))/2*fs);
case 2
idx_50TT{j}(t,tt)= round((gait_events{j}{7,t}(2,1) + gait_events{j}{5,t}(end,1))/2*fs);
end
else
disp('Not a LL or RR subject');
end
end
end
end
end
The code is running properly but I am getting 10 of:
ans =
logical
1
in the command window. This is the first time I use switch. Is that causing it? how do I fix the code so I don't get the logical answers.
Thanks!
  1 个评论
ErikaZ
ErikaZ 2019-3-1
I made a correction of the location of the for t=1:10 loop. I stil have a logical output but ONLY ONE time.
for j = 2:3
%for t= 1:10
if j==2 % Stairs up
for t=1:10
for tt=1:2
if length(gait_events{j}{1,t})==3 && length(gait_events{j}{5,t})==3 && strcmp(side,'Left') % Left leg analyzed, starts with Left Leg
switch tt
case 1
idx_50TT{j}(t,tt)= round((gait_events{j}{3,t}(1,1) + gait_events{j}{7,t}(1,1))/2*fs);
case 2
idx_50TT{j}(t,tt)= round((gait_events{j}{3,t}(end,1) + gait_events{j}{2,t}(end,1))/2*fs);
end
elseif length(gait_events{j}{1,t})==3 && length(gait_events{j}{5,t})==3 && strcmp(side,'Right') % Right leg analyzed, starts with Right Leg
switch tt
case 1
idx_50TT{j}(t,tt)= round((gait_events{j}{3,t}(1,1) + gait_events{j}{7,t}(1,1))/2*fs);
case 2
idx_50TT{j}(t,tt)= round((gait_events{j}{7,t}(end,1) + gait_events{j}{6,t}(end,1))/2*fs);
end
else
disp('Not a LL or RR subject');
end
end
end
else j==3 % Stairs down
for t=1:10
for tt=1:2
if length(gait_events{j}{1,t})==3 && length(gait_events{j}{5,t})==3 && strcmp(side,'Left') %Left leg analyzed, starts with Left Leg
switch tt
case 1
idx_50TT{j}(t,tt)= round((gait_events{j}{8,t}(1,1) + gait_events{j}{5,t}(1,1))/2*fs);
case 2
idx_50TT{j}(t,tt)= round((gait_events{j}{3,t}(2,1) + gait_events{j}{1,t}(end,1))/2*fs);
end
elseif length(gait_events{j}{1,t})==3 && length(gait_events{j}{5,t})==3 && strcmp(side,'Right') % Right leg analyzed, starts with Right Leg
switch tt
case 1
idx_50TT{j}(t,tt)= round((gait_events{j}{4,t}(1,1) + gait_events{j}{1,t}(1,1))/2*fs);
case 2
idx_50TT{j}(t,tt)= round((gait_events{j}{7,t}(2,1) + gait_events{j}{5,t}(end,1))/2*fs);
end
else
disp('Not a LL or RR subject');
end
end
end
end
%end
end

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2019-3-1
else j==3
is the same as
else
disp(j==3)

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by