Subscript indices must either be real positive integers or logicals. where I have to change or update the code

1 次查看(过去 30 天)
clc;
clear all;
close all;
Transmitted_Message = 'SP22';
dec = double(Transmitted_Message); % text to ASCII (decimal)
p2 = 2.^(0:-1:-7); % 2^0,2^-1,.......,2^-7
B = mod(floor(p2'*dec),2); % decimal to binary conversion
% columns of B are bits of characters
x = reshape(B,1,numel(B));
disp('Transmitted message is:')
disp(Transmitted_Message)
disp('Binary information at Transmitter:');
disp(x);
F=1;
G=9;
%my id is 19-39319-1
br=(F+G+2)*200;
bp = 1/br;% bit period
%% representation of transmitting binary information as digital % signal
bit = [];
a0 = 12; % amplitude for binary bit 00
a1 = 16; % amplitude for binary bit 01
a2=20; % amplitude for binary bit 10
a3=24;% amplitude for binary bit 11
nt = 1000; % number of samples in a single bit period
for n =linspace(1,2,length(x))
if x(n) == 0 && x(n+1)== 0 ;
se = a0*ones(1,nt);
elseif x(n) == 0 && x(n+1)== 1;
se = a1*ones(1,nt);
elseif x(n) == 1 && x(n+1)== 0;
se = a2*ones(1,nt);
else x(n) == 1 && x(n+1)== 1;
se = a3*ones(1,nt);
end
bit = [bit se];
end
t = linspace(0, bp/nt, length(x)*bp-bp/nt));
plot (t,bit,'lineWidth',2);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('Transmitting information as digital signal');

采纳的回答

Shnigdha Sharup
Shnigdha Sharup 2021-8-4
remove linspace . write 2*bp/nt insted of bp/nt in t.

更多回答(1 个)

Asaad Abboud Alkhalaf
instead of for n =linspace(1,2,length(x))
use for n= 1:2:length(x) if you want vector with elements spaced by 2
or for n=1:length(x) if you want vector with ellemnts spaced by1

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by