Legend with text and values of array
Ältere Kommentare anzeigen
I have the following code, producing 10 different lines in one graph. Each of these lines correspond to a certain variance of a, for which I want to create a legend.
With the current code, the legend just states "data1, data2,data3 etc" for each line.
I want the values of the array variance_a, which I produce outside of the for loop, to match data 1, data2,data3 etc and to add the text "variance_a=" in front of the value. In short, I want the legend to look like this:
variance_a= (first output of variance_a array)
variance_a=(second output of variance_a array)
etc.
I can't seem to figure out how to call values out of the array to the legend, and I want to avoid having to enter each input bij hand, as the number of values in variance_a needs to be changed. Any help here?
sample=10000;
s = -1 + (2).*rand(sample,1);
s = nonzeros(s);
s(s<0)=-1;
s(s>0)=1;
change_a=0.2:0.2:2
variance_a=sqrt(change_a)*(1/12)
for i=1:length(change_a)
%Define Channel
change_n=0:0.2:2;
a=change_a(i)*rand(sample,1);
n=change_n.*randn(sample,1);
%channel output
y=a.*s+n;
%Define received signal as negative y equals -1 and positive y equals 1
z=y;
z(y<0)=-1;
z(y>0)=1;
%compare source signal to received signal
c=z==s;
for i=1:size(z,2)
errors(i)=size(z,1)-nnz(c(:,i));
error_percent=errors./(size(z,1))*100.
end
%plot for each value of change_a a line
plot(var(n),error_percent)
xlabel('variance noise')
ylabel('error percentage')
hold on
end
legend()
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Legend finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
