explanation of the matlab code

2 vues (au cours des 30 derniers jours)
Waseem Abbas
Waseem Abbas le 25 Mai 2022
Commenté : Walter Roberson le 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?

Réponse acceptée

Walter Roberson
Walter Roberson le 25 Mai 2022
Modifié(e) : Walter Roberson le 25 Mai 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;

Plus de réponses (1)

siva sreedhar
siva sreedhar le 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 commentaire
Walter Roberson
Walter Roberson le 24 Sep 2022
This does not appear to answer the question created by Waseem?

Connectez-vous pour commenter.

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by