Help - How to plot a graph with multiple colors?

3 次查看(过去 30 天)
I'm trying to plot a graph where I can observe the points of the equation (in the sequence of bits 0 and 1). Each set will have a marker and a different color.
I am using the following code:
L = 1e4; %number of bits
SNRdB = -10:2:20;
SNR = 10.^(SNRdB/10);
alpha = 0.3;
cor = 'rbmkg'; % indicate bits an and bn
ident= '*xv+>'; % indicate bits dI and dQ
for count=1:length(SNRdB)
an = 2*randi([ 0 1 ],1,L)-1;
bn = 2*randi([ 0 1 ],1,L)-1;
dI = 2*randi([ 0 1 ],1,L)-1;
dQ = 2*randi([ 0 1 ],1,L)-1;
sn = an .* ( sqrt(1-alpha) + sqrt(alpha) .* dI ) + 1i .* bn .* ( sqrt(1-alpha) + sqrt(alpha) .* dQ );
end
k=1;
str=[];
figure;
for k1 = 1:4
for k2 = 1:4
str =[ str; num2str(max(an(k1),0)) num2str(max(bn(k1),0)) num2str(max(dI(k2),0)) num2str(max(dQ(k2),0))];
scatter(real(sn(k)),imag(sn(k)),[cor(k1) ident(k2)]);
hold on
k = k+1;
end
end
title('symbols')
legend(str);
axis([-2 3 -2 2])
I'm having as answer the following graph:
I don't know where I'm going wrong.
I would like to obtain a graph with all the combinations and respective colors as follows:

回答(2 个)

Walter Roberson
Walter Roberson 2021-5-31
for k1 = 1:4
for k2 = 1:4
str =[ str; num2str(max(an(k1),0)) num2str(max(bn(k1),0)) num2str(max(dI(k2),0)) num2str(max(dQ(k2),0))];
scatter(real(sn(k)),imag(sn(k)),[cor(k1) ident(k2)]);
hold on
k = k+1;
end
end
You are only plotting from the first 4 * 4 = 16 elements of sn, but the first 16 elements of sn might happen to not represent all of the bit combinations. Your sn is length 10000
You can instead do something like
U = uniquetol([real(sn).', imag(sn).'], 'byrows', true);
Ui = complex(U(:,1), U(:,2));
now Ui will be the (16) unique complex values, and you can plot them. However, you will need to figure out which one corresponds to which pattern of bits.
  6 个评论
adriane duarte
adriane duarte 2021-6-1
the model is giving an error on the line:
[wasfound, idx] = ismembertol(Ui, Sn(:));
"Error using ismembertol
Input A must be a real full matrix of type single or double."
Walter Roberson
Walter Roberson 2021-6-1
[wasfound, idx] = ismembertol([real(Ui(:)), imag(Ui(:))], [real(Sn(:)), imag(Sn(:))], 'byrows', true);

请先登录,再进行评论。


Sulaymon Eshkabilov
Hi,
Here are corrected part of your script:
...
for k1 = 1:4
for k2 = 1:4
str =[ str; num2str(max(an(k1),0)) num2str(max(bn(k1),0)) num2str(max(dI(k2),0)) num2str(max(dQ(k2),0))];
scatter(real(sn(k1)),imag(sn(k2)),[cor(k1) ident(k2)]);
hold on
end
end
...
Good luck.

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by