Help with populating a vector with 2 random variables

New to MATLAB and need to figure out how to populate a vetor with 2 random variables on both the negative and positive side of 0.
my variables are: 'numChannels' and 'channelSize' and would like to populate a vector of 'values = [ ]'
example1:
'numChannels = 3'
'channelSize = 1'
i would expect an output of 'values = [ -1, 0, 1]'
example2:
'numChannels = 5'
'channelSize = 0.5'
i would expect an output of 'values = [ -1, -0.5, 0, 0.5, 1]'
Any help would be greatly appreciated. Thanks

 採用された回答

Voss
Voss 2024 年 1 月 11 日

0 投票

max_value = (numChannels-1)/2*channelSize;
values = linspace(-max_value, max_value, numChannels);

2 件のコメント

Jason
Jason 2024 年 1 月 11 日
Thank you so much, worked great!
Voss
Voss 2024 年 1 月 11 日
You're welcome!

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

その他の回答 (0 件)

カテゴリ

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

製品

リリース

R2012a

タグ

質問済み:

2024 年 1 月 11 日

コメント済み:

2024 年 1 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by