why temp command is required

Is there any specific reason for using temp in coding

3 件のコメント

Stephen23
Stephen23 2017 年 11 月 7 日
編集済み: Stephen23 2017 年 11 月 7 日
What is temp? A function name, a filename, a variable name, a class name, a method name, or something else? How is it being used?
Prabha Kumaresan
Prabha Kumaresan 2017 年 11 月 7 日
編集済み: Guillaume 2017 年 11 月 7 日
in the below coding temp was being used
ratio=0.1; %Td over Tb: delay spread relative to OFDM frame duration
c=2*pi*ratio;
for j=1:Nuser
temp=[];
for n=1:Ncarrier
nc=(n-1)*c;
entry=(1+i*nc)/(1+nc^2);
temp=[temp entry];
end
Rchan=toeplitz(temp);
could you tell me the working of it.
Stephen23
Stephen23 2017 年 11 月 7 日
temp is not a command as you wrote in your question. It is an array which is used to collect the values of entry into one larger array.

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

回答 (1 件)

Guillaume
Guillaume 2017 年 11 月 7 日

0 投票

temp is a poor name for a variable. It's obviously a temporary variable used to calculate something but it doesn't tell you what.
In any case, in your code snippet, temp is not necessary and the way it's calculated is very inefficient. 1) temp could have been preallocated to avoid the resizing at each step of the loop, since it's final size is know:
temp = zeros(1, Ncarrier);
for ...
temp(n) = ...
end
But the loop is not even needed:
for j = 1:Nuser
nc = ((1:Ncarrier)-1)*c;
entry = (1+i*nc) ./ (1+nc/^2);
temp = entry; %or simply use entry instead of temp
...
end
As to why the name temp was chosen, or why it was created, you can only ask the author of this poorly written code.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2017 年 11 月 7 日

回答済み:

2017 年 11 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by