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

조회 수: 2 (최근 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
Asaad Abboud Alkhalaf 2021년 8월 3일
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