To make coding simplier and have the same plot
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Rik
le 8 Déc 2019
Modifié(e) : Rik
le 9 Déc 2019
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!