Why is my script not enterering the elseif argument

1 次查看(过去 30 天)
tasks = {'hop_inv','hop_uninv'};
tasks_name = tasks; % for plot title
SIDE = {'ipsilateral'};
JOINTS ={'ankle','knee','hip'};
% groups to plot for comparison (küerzel, timepoint)
COMPARISON = [{'SBA','baseline'}; ...
{'SBA','0mt'}];
COLOR = {'b','r'};
COLOR2 = {'c','m'};
test = [COMPARISON,tasks'];
for subj = 1:size(sub.([COMPARISON{1,1},'_',COMPARISON{1,2}]),2)
plot_setup_SkinMarker
set(0,'CurrentFigure',f1);
for grp = 1:size(COMPARISON,1)
group = [COMPARISON{grp,1},'_',COMPARISON{grp,2}];
for sde=1:length(SIDE) % Seite
for tsk= 1:length(tasks)
for jo = 1:length(JOINTS)
movement_tmp = fieldnames(sub.(group)(subj).(tasks{tsk}).(SIDE{sde}).(JOINTS{jo}));
movement = [movement_tmp(1),movement_tmp(4),movement_tmp(7)];
if strcmp(JOINTS{jo},'ankle')
movement = {'dflex','add','eversion'};
else
movement = {'flex','abd','extrot'};
end
k=[1,4,7;2,8,5;3,9,6];
for moNr = 1:length(movement)
ka=k(jo,moNr); % which plot (= which axis)
% set sign
if (strcmp(JOINTS{jo},'ankle')&&strcmp(movement{moNr},'eversion'))...
||(strcmp(JOINTS{jo},'knee')&&strcmp(movement{moNr},'abd'))...
||(strcmp(JOINTS{jo},'knee')&&strcmp(movement{moNr},'extrot'))...
||(strcmp(JOINTS{jo},'hip')&&strcmp(movement{moNr},'abd'))...
||(strcmp(JOINTS{jo},'hip')&&strcmp(movement{moNr},'extrot'))
sign=-1;
else
sign=1;
end
set(f1,'CurrentAxes',ha(ka));
mean = sign*(sub.(group)(subj).(tasks{tsk}).(SIDE{sde})...
.(JOINTS{jo}).([movement{moNr} '_mean']));
SD = sub.(group)(subj).(tasks{tsk}).(SIDE{sde}).(JOINTS{jo})...
.([movement{moNr} '_std']);
if grp == 1 %baseline group
p(tsk) = plot(mean,COLOR{tsk},'LineWidth',1.0);
plot(mean + SD,COLOR{tsk},'LineWidth',0.1,'LineStyle','--')
plot(mean - SD,COLOR{tsk},'LineWidth',0.1,'LineStyle','--')
elseif grp == 2
q(tsk) = plot(mean,COLOR2{tsk},'LineWidth',1.0);
plot(mean + SD,COLOR2{tsk},'LineWidth',0.1,'LineStyle','--')
plot(mean - SD,COLOR2{tsk},'LineWidth',0.1,'LineStyle','--')
end
clearvars SD to_plot
end
end
end % group
% legende
legend(ha(9),[p,q],[strjoin([test(1,2),'_',test(1,3)]), strjoin([test(1,2),'_',test(2,3)]), strjoin([test(2,2),'_',test(1,3)]), strjoin([test(2,2),'_',test(2,3)])],...
'Location','southeast','Orientation','horizontal','FontSize',5.5,'NumColumns',1);
it is a pre-existing script, which I tried to change so that the output plot consists 4 means mit std. I want to have them 4 different colors. The original only consisted of the p(tsk) = plot(..) without any if/else argument. Now I added an variable COLOR2 with two extra colors and this if/else but it never enters the elseif and misses the variable q in the legend function. I know it's a pretty long code, but maybe someone can help.
Cheers Marcel

回答(1 个)

Walter Roberson
Walter Roberson 2022-5-11
end % group
No, that is incorrect. You have for moNr, within for jo, within for tsk, so that "end" is matching tsk. You do the legend() at that point assuming that p and q have both been assigned to. But q is assigned to when grp changes. Your call to legend is within for sde which is within for grp so it will be a while before you see a change in grp.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by