Code generates one more column than needed
Ältere Kommentare anzeigen
Hello!
I'm new to Matlab. For some reason, I can't generate 'mr' to be the same size as 'm'. 'm' comes out to be 1280 columns, whereas 'mr' is always 1281 columns.
'm' is supposed to be data of 1-0-1-0, and 'mr' is supposed to be data derived from four random bits.
Here is the relevant code:
clear all;
fs=320; % sampling rate
ts=1/fs; % sampling interval
fc=10; % carrier frequency
T=4; % total simulation time
D=1; % data pulse duration 1s
L=D/ts; % the number of samples for one data pulse
HL=ones(1,L); % for logic '1'
LL=-ones(1,L); % for logic '0'
m=[]; % set to empty vector for initiation
for i=1:T/D % Generate the message signal
if mod(i,2)==1
m=[m HL]; % dump the logic '1'
else
m=[m LL]; % dump the logic '0'
end
end
rnum=rand(1,4) > 0.5;
i=1;
for i=1:T/D
for j=1:L
if rnum(i) == 0
mr=[m 0];
elseif rnum(i) == 1
mr=[m 1];
end
end
end
Thanks in advance for assistance!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Matrices and Arrays 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!