To make coding simplier and have the same plot
2 次查看(过去 30 天)
显示 更早的评论
Is there any ways to make my coding simplier at the same time keep my plot result as same as my original one?
retint05 = 5
retint1 = 10
retint2 = 20
retint3 = 30
dist05 = log([10:-1:1]+retint05);
dist1 = log([10:-1:1]+retint1)
dist2 = log([10:-1:1]+retint2)
dist3 = log([10:-1:1]+retint3)
eta05 = exp(-c*abs(dist05-dist05(:)));
discrim05 = 1./sum(eta05,1)
eta1 = exp(-c*abs(dist1-dist1(:)));
discrim1 = 1./sum(eta1,1)
eta2 = exp(-c*abs(dist2-dist2(:)));
discrim2 = 1./sum(eta2,1)
eta3 = exp(-c*abs(dist3-dist3(:)));
discrim3 = 1./sum(eta3,1)
hold on
plot(discrim05,'-mo','Displayname','interval = 5');
plot(discrim1,'-ro','Displayname','interval = 10');
plot(discrim2,'-go','Displayname','interval = 20');
plot(discrim3,'-yo','Displayname','interval = 30') ;
axis([0 length(dist) 0 1]) ;
title({'SIMPLE Memory Model'...
'\fontsize{9}\color{blue}Length = 10; Retetion Interval = 0'...});
xlabel('Serial Position','fontsize',14) ;
ylabel('Discriminability','fontsize',14);
lgd = legend ('Location','northwest');
lgd.NumColumns = 4;
lgd.FontSize = 6;
set(gcf, 'color', 'white');
hold off
0 个评论
采纳的回答
Rik
2019-12-8
编辑:Rik
2019-12-9
You could vectorize this, but using a loop is much easier and will probably have the same performance.
Here is an example for the code you posted:
c=20;%I added this to make the code run
retint_vector=[5 10 20 30];
plotcolors={'m','r','g','y'};%you can also omit this and let Matlab generate colors
for n=1:numel(retint_vector)
retint=retint_vector(n);
dist = log((10:-1:1)+retint);
eta = exp(-c*abs(dist-dist(:)));
discrim = 1./sum(eta,1);
hold on
plot(discrim,['-' plotcolors{n} 'o'],...
'Displayname',sprintf('interval = %d',retint));
hold off
end
axis([0 length(dist) 0 1]) ;
title({'SIMPLE Memory Model'...
'\fontsize{9}\color{blue}Length = 10; Retetion Interval = 0'});
xlabel('Serial Position','fontsize',14) ;
ylabel('Discriminability','fontsize',14);
lgd = legend('Location','northwest');
lgd.NumColumns = 4;
lgd.FontSize = 6;
set(gcf, 'color', 'white');
hold off
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!