explanation of the matlab code

1 visualización (últimos 30 días)
Waseem Abbas
Waseem Abbas el 25 de Mayo de 2022
Comentada: Walter Roberson el 24 de Sept. de 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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Mayo de 2022
Editada: Walter Roberson el 25 de Mayo de 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;

Más respuestas (1)

siva sreedhar
siva sreedhar el 24 de Sept. de 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 comentario
Walter Roberson
Walter Roberson el 24 de Sept. de 2022
This does not appear to answer the question created by Waseem?

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by