Matlab, looking to place the next value from an array in the legend each time a loop executes -
i trying legend show fixed value , 1 array. have managed fixed value display , when manually enter position array display. want position selected array advance 1 each time. tried use n variable have defined in script doesn't seem work. @ moment have entered value of 4 , selects 4th value array. new matlab , can't life of me think how this. appreciated. here script working with.
clear clc f = @(x,k,lamda) ((lamda.^k).*(x.^(k-1)).*(exp(-lamda.*x))./(factorial(k-1))); colors = ['k', 'r' , 'g', 'b', 'y', 'm', 'c']; hold on n=1; k = 5; x = 0 :0.1: 10; lamda = 1 : 0.2 : 2; ncol= mod(n,7)+1; plot(x,f(x,k,lamda), 'color', colors(ncol)) l = 1 : 0.2 : 2; legstr(n,:) = strcat ('k = ', num2str(k), ' lamda = ', num2str (l(4))); legend(legstr) title('erlang distribution') xlabel('x') ylabel('f(x,k,lamda)') n=n+1; end hold off
you there. no need introduce vector pull since value have assigned lamda
in each loop iteration work. you'll have change legstr
matrix cell array deal fact lamda
has digit in decimal place, cause legend string longer or shorter, depending.
clear clc f = @(x,k,lamda) ((lamda.^k).*(x.^(k-1)).*(exp(-lamda.*x))./(factorial(k-1))); colors = ['k', 'r' , 'g', 'b', 'y', 'm', 'c']; hold on n=1; k = 5; x = 0 :0.1: 10; lamda = 1 : 0.2 : 2; ncol= mod(n,7)+1; plot(x,f(x,k,lamda), 'color', colors(ncol)) % l = 1 : 0.2 : 2; legstr{n} = strcat ('k = ', num2str(k), ' lamda = ', num2str (lamda)); legend(legstr) title('erlang distribution') xlabel('x') ylabel('f(x,k,lamda)') n=n+1; end hold off
Comments
Post a Comment