explanation of the matlab code

1 回表示 (過去 30 日間)
Waseem Abbas
Waseem Abbas 2022 年 5 月 25 日
コメント済み: Walter Roberson 2022 年 9 月 24 日
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?

採用された回答

Walter Roberson
Walter Roberson 2022 年 5 月 25 日
編集済み: Walter Roberson 2022 年 5 月 25 日
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;

その他の回答 (1 件)

siva sreedhar
siva sreedhar 2022 年 9 月 24 日
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 件のコメント
Walter Roberson
Walter Roberson 2022 年 9 月 24 日
This does not appear to answer the question created by Waseem?

サインインしてコメントする。

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by