explanation of the matlab code
1 view (last 30 days)
Show older comments
Waseem Abbas
on 25 May 2022
Commented: Walter Roberson
on 24 Sep 2022
for j=0:8
if(decision==j)
rentedforVector(count, j+1) = 1;
else
rentedforVector(count, j+1) = 0;
end
prevmov= mov;
end
please explain this slice of code?
0 Comments
Accepted Answer
Walter Roberson
on 25 May 2022
Edited: Walter Roberson
on 25 May 2022
Equivalent code:
rentedforVector(count, 1:9) = decision == (0:8);
With no for loop.
If decision is 0 then the first column is set to 1. If decision is 1 then set the second column to 1, and so on.
In the special case that the array already exists and is already the correct size and is already initialized to 0, and decision is in the range 0 to 8,then you can simplify to
rentedforVector(count, decision+1) = 1;
0 Comments
More Answers (1)
siva sreedhar
on 24 Sep 2022
clc;
clear all;
b=input('Enter Quantization Interval:: ');
t = 0:0.0005:10;
% Representation of the Message Signal
x = sin(t);
subplot(3,1,1);
plot(t,x,'black');
title('Message Signal');
xlabel('Time(s) ---->')
ylabel('Amplitude(V) ---->')
legend('Message Signal ---->');
grid on
% Representation of the Quantized Signal
partition = -1:0.1:b;
codebook = -1:0.1:(b+0.1);
[index,quants] = quantiz(x,partition,codebook);
subplot(3,1,2);
plot(t,quants);
title('Quantized Signal');
xlabel('Samples ---->')
ylabel('Amplitude(V) ---->')
legend('Quantized Signal ---->');
grid on
% Representation of the PCM Signal
y = uencode(quants,3);
subplot(3,1,3);
plot(t,y,'red');
title('PCM Signal');
xlabel('Samples ---->');
ylabel('Amplitude(V) ---->')
legend('PCM Signal ---->');
grid on
% Add title to the Overall Plot
ha = axes ('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text (0.5, 1,'\bf Pulse Code Modulation ','HorizontalAlignment','center','VerticalAlignment', 'top')
1 Comment
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!