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일
max_value = (numChannels-1)/2*channelSize;
values = linspace(-max_value, max_value, numChannels);

댓글 수: 2

Thank you so much, worked great!
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup 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