variance for an array

5 ビュー (過去 30 日間)
Vc27
Vc27 2022 年 12 月 27 日
編集済み: John D'Errico 2022 年 12 月 27 日
I have a value for the variance and need to assign this value to each component in a 200 component array, is there a way to assign the var to each component in a for loop? thanks in advance

回答 (1 件)

John D'Errico
John D'Errico 2022 年 12 月 27 日
編集済み: John D'Errico 2022 年 12 月 27 日
Why would you need a for loop?
V = 42; % you don't tell us what is the variance. So that is my choice. 42 is the answer to all questions, as I have learned
Varray1 = repmat(V,1,200); % One option
Varray2 = V*ones(1,200); % another
Varray3 = V + zeros(1,200); % or this
Varray4 = kron(V,ones(1,200)); % or this
Varray5 = zeros(1,200); Varray5(:) = V; % Or this
Varray6 = linspace(V,0,200) + linspace(0,V,200); % or, if you want a totally silly way
Ok, many of those solutions are pretty silly.
Do you want to bet that I can't come up with at least a dozen solutions, none of which need a loop?

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by