How to combine multiple plots using subplot

15 Ansichten (letzte 30 Tage)
ethan watts
ethan watts am 26 Apr. 2022
I'm new to matlab and am having showing all 16 graphs only a few to be showing up. The current code is:
clear
clc
N = 256;
n = 0:N-1;
x0000 = [ones(16,1); zeros(240,1)];
x0000 = x0000/norm(x0000);
x0001 = [zeros(16,1); ones(16,1); zeros(224,1)];
norm(x0001);
x0001 = x0001/norm(x0001);
x0010 = [zeros(32,1); ones(16,1); zeros(208,1)];
norm(x0010);
x0010 = x0010/norm(x0010);
x0011 = [zeros(48,1);ones(16,1); zeros(192,1)];
norm(x0011);
x0011 = x0011/norm(x0011);
x0100 = [zeros(64,1);ones(16,1); zeros(176,1)];
norm(x0100);
x0100 = x0100/norm(x0100);
x0101 = [zeros(80,1); ones(16,1); zeros(160,1)];
norm(x0101);
x0101 = x0101/norm(x0101);
x0110 = [zeros(96,1); ones(16,1); zeros(144,1)];
norm(x0110);
x0110 = x0110/norm(x0110);
x0111 = [zeros(112,1); ones(16,1); zeros(128,1)];
norm(x0111);
x0111 = x0111/norm(x0111);
x1000 = [zeros(128,1); ones(16,1); zeros(112,1)];
norm(x1000);
x1000 = x1000/norm(x1000);
x1001 = [zeros(144,1); ones(16,1); zeros(96,1)];
norm(x1001);
x1001 = x1001/norm(x1001);
x1010 = [zeros(160,1); ones(16,1); zeros(80,1)];
norm(x1010);
x1010 = x1010/norm(x1010);
x1011 = [zeros(176,1); ones(16,1); zeros(64,1)];
norm(x1011);
x1011 = x1011/norm(x1011);
x1100 = [zeros(192,1); ones(16,1); zeros(48,1)];
norm(x1100);
x1100 = x1100/norm(x1100);
x1101 = [zeros(208,1); ones(16,1); zeros(32,1)];
norm(x1101);
x1101 = x1101/norm(x1101);
x1110 = [zeros(224,1); ones(16,1); zeros(16,1)];
norm(x1110);
x1110 = x1110/norm(x1110);
x1111 = [zeros(240,1); ones(16,1)];
norm(x1111);
x1111 = x1111/norm(x1111);
signals=[x0000,x0001,x0010,x0011,x0100,x0101,x0110,x0111,x1000,x1001,x1010,x1011,x1100,x1101,x1110,x1111];
subplot(911);
stem(n,x0000, 'b','Marker','none','LineWidth',1)
title('Signal x0000 - Transmit to send a digital 0000','fontSize',18)
subplot(912);
stem(n,x0001, 'r','Marker','none','LineWidth',1)
title('Signal x0001 - Transmit to send a digital 0001','fontSize',18)
subplot(913);
stem(n,x0010, 'r','Marker','none','LineWidth',1)
title('Signal x0010 - Transmit to send a digital 0010','fontSize',18)
subplot(914);
stem(n,x0011, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 0011','fontSize',18)
subplot(915);
stem(n,x0100, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 0100','fontSize',18)
subplot(916);
stem(n,x0101, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 0101','fontSize',18)
subplot(917);
stem(n,x0110, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 0110','fontSize',18)
subplot(918);
stem(n,x0111, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 0111','fontSize',18)
subplot(919);
stem(n,x1000, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1000','fontSize',18)
subplot(921);
stem(n,x1001, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1001','fontSize',18)
subplot(922);
stem(n,x1010, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1010','fontSize',18)
subplot(923);
stem(n,x1011, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1011','fontSize',18)
subplot(924);
stem(n,x1100, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1100','fontSize',18)
subplot(925);
stem(n,x1101, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1101','fontSize',18)
subplot(926);
stem(n,x1110, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1110','fontSize',18)
subplot(927);
stem(n,x1111, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1111','fontSize',18)
noisefactor = 0.2
TX = randi([1 16]);
y=signals(:,TX) + noisefactor*randn(size(x0000));
y=y./norm(y); % normalize y
subplot(928)
stem(L,L,'k','Marker','none','LineWidth',1)
title('Received signal - Which Symbol is it?','fontSize',18)
%compute the inter products between y and all of the symbols:
innerproductsym0000 = abs (dot(y,x0000) )
innerproductsym0001 = abs (dot(y,x0001) )
innerproductsym0010 = abs (dot(y,x0010) )
innerproductsym0011 = abs (dot(y,x0011) )
innerproductsym0100 = abs (dot(y,x0100) )
innerproductsym0101 = abs (dot(y,x0101) )
innerproductsym0110 = abs (dot(y,x0110) )
innerproductsym0111 = abs (dot(y,x0111) )
innerproductsym1000 = abs (dot(y,x1000) )
innerproductsym1001 = abs (dot(y,x1001) )
innerproductsym1010 = abs (dot(y,x1010) )
innerproductsym1011 = abs (dot(y,x1011) )
innerproductsym1100 = abs (dot(y,x1100) )
innerproductsym1101 = abs (dot(y,x1101) )
innerproductsym1110 = abs (dot(y,x1110) )
innerproductsym1111 = abs (dot(y,x1111) )
  2 Kommentare
Jan
Jan am 26 Apr. 2022
If you do not hide an index in the name of the variable as in "x0000", but use an array instead, the code could be simplified massively using loops.
The notation "subplot(928)" is outdated for over 25 years now. Prefer the modern subplot(9, 2, 8).
You post some code. What is your question? What do you want to "combine" and how?
ethan watts
ethan watts am 27 Apr. 2022
yes my question is how can i go about making all 16 graphs plot in the run window the current code is giving me this, and it is still missing 3 out of the 13 plots

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Johannes Hougaard
Johannes Hougaard am 27 Apr. 2022
You have to define all your subplots in the [9 2] grid - the code you present show the first 9 graphs in a [9 1] grid and the last 7 in a [9 2] grid.
That would be that you change the code to
subplot(9,2,1);
stem(n,x0000, 'b','Marker','none','LineWidth',1)
title('Signal x0000 - Transmit to send a digital 0000','fontSize',18)
subplot(9,2,2);
stem(n,x0001, 'r','Marker','none','LineWidth',1)
title('Signal x0001 - Transmit to send a digital 0001','fontSize',18)
% Many lines to follow until
subplot(9,2,10);
stem(n,x1001, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1001','fontSize',18)
subplot(9,2,11);
stem(n,x1010, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1010','fontSize',18)
% Finishing with
subplot(9,2,16);
stem(n,x1111, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1111','fontSize',18)
noisefactor = 0.2
TX = randi([1 16]);
y=signals(:,TX) + noisefactor*randn(size(x0000));
y=y./norm(y); % normalize y
subplot(9,2,17)
stem(L,L,'k','Marker','none','LineWidth',1)
title('Received signal - Which Symbol is it?','fontSize',18)
Which for your full code could be something like this
clear
clc
N = 256;
n = 0:N-1;
x0000 = [ones(16,1); zeros(240,1)];
x0000 = x0000/norm(x0000);
x0001 = [zeros(16,1); ones(16,1); zeros(224,1)];
norm(x0001);
x0001 = x0001/norm(x0001);
x0010 = [zeros(32,1); ones(16,1); zeros(208,1)];
norm(x0010);
x0010 = x0010/norm(x0010);
x0011 = [zeros(48,1);ones(16,1); zeros(192,1)];
norm(x0011);
x0011 = x0011/norm(x0011);
x0100 = [zeros(64,1);ones(16,1); zeros(176,1)];
norm(x0100);
x0100 = x0100/norm(x0100);
x0101 = [zeros(80,1); ones(16,1); zeros(160,1)];
norm(x0101);
x0101 = x0101/norm(x0101);
x0110 = [zeros(96,1); ones(16,1); zeros(144,1)];
norm(x0110);
x0110 = x0110/norm(x0110);
x0111 = [zeros(112,1); ones(16,1); zeros(128,1)];
norm(x0111);
x0111 = x0111/norm(x0111);
x1000 = [zeros(128,1); ones(16,1); zeros(112,1)];
norm(x1000);
x1000 = x1000/norm(x1000);
x1001 = [zeros(144,1); ones(16,1); zeros(96,1)];
norm(x1001);
x1001 = x1001/norm(x1001);
x1010 = [zeros(160,1); ones(16,1); zeros(80,1)];
norm(x1010);
x1010 = x1010/norm(x1010);
x1011 = [zeros(176,1); ones(16,1); zeros(64,1)];
norm(x1011);
x1011 = x1011/norm(x1011);
x1100 = [zeros(192,1); ones(16,1); zeros(48,1)];
norm(x1100);
x1100 = x1100/norm(x1100);
x1101 = [zeros(208,1); ones(16,1); zeros(32,1)];
norm(x1101);
x1101 = x1101/norm(x1101);
x1110 = [zeros(224,1); ones(16,1); zeros(16,1)];
norm(x1110);
x1110 = x1110/norm(x1110);
x1111 = [zeros(240,1); ones(16,1)];
norm(x1111);
x1111 = x1111/norm(x1111);
signals=[x0000,x0001,x0010,x0011,x0100,x0101,x0110,x0111,x1000,x1001,x1010,x1011,x1100,x1101,x1110,x1111];
fh = figure;
ii = 1;
subplot(9,2,ii); ii = ii+1;
stem(n,x0000, 'b','Marker','none','LineWidth',1)
title('Signal x0000 - Transmit to send a digital 0000','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x0001, 'r','Marker','none','LineWidth',1)
title('Signal x0001 - Transmit to send a digital 0001','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x0010, 'r','Marker','none','LineWidth',1)
title('Signal x0010 - Transmit to send a digital 0010','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x0011, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 0011','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x0100, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 0100','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x0101, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 0101','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x0110, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 0110','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x0111, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 0111','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x1000, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1000','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x1001, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1001','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x1010, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1010','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x1011, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1011','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x1100, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1100','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x1101, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1101','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x1110, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1110','fontSize',18)
subplot(9,2,ii); ii = ii+1;
stem(n,x1111, 'r','Marker','none','LineWidth',1)
title('Signal x11 - Transmit to send a digital 1111','fontSize',18)
noisefactor = 0.2;
TX = randi([1 16]);
y=signals(:,TX) + noisefactor*randn(size(x0000));
y=y./norm(y); % normalize y
subplot(9,2,ii); ii = ii+1; clear ii
stem(L,L,'k','Marker','none','LineWidth',1)
Unrecognized function or variable 'L'.
title('Received signal - Which Symbol is it?','fontSize',18)
fh.WindowState = 'maximized'; clear fh

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by