Help - How to plot a graph with multiple colors?

1 回表示 (過去 30 日間)
adriane duarte
adriane duarte 2021 年 5 月 31 日
コメント済み: Walter Roberson 2021 年 6 月 1 日
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
Sulaymon Eshkabilov 2021 年 5 月 31 日
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.
  1 件のコメント
adriane duarte
adriane duarte 2021 年 5 月 31 日
hi!!
I tested it that way but it still didn't work. Missing a combination.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by