how to insert same scalar as length of something?

1 回表示 (過去 30 日間)
Sierra
Sierra 2022 年 8 月 23 日
回答済み: Steven Lord 2022 年 8 月 23 日
Let's suppose, A = [1, 2, 3, 4, 5] and B = [0].
I want to make second [0,0,0,0,0] whose length is 5.
Please Let me know how to do this

採用された回答

Steven Lord
Steven Lord 2022 年 8 月 23 日
If you want to replicate the scalar in B to be the same size as A, you can use repmat. If you know that B will always be 0, instead I'd just use the zeros function.
A = ones(3, 4)
A = 3×4
1 1 1 1 1 1 1 1 1 1 1 1
B = pi
B = 3.1416
C = repmat(B, size(A))
C = 3×4
3.1416 3.1416 3.1416 3.1416 3.1416 3.1416 3.1416 3.1416 3.1416 3.1416 3.1416 3.1416
D = zeros(size(A))
D = 3×4
0 0 0 0 0 0 0 0 0 0 0 0

その他の回答 (1 件)

Abderrahim. B
Abderrahim. B 2022 年 8 月 23 日
編集済み: Abderrahim. B 2022 年 8 月 23 日
Is this what you are trying to do?
A = [1,2,3,4,5] ;
myScalar = 2 ; % change this to the scalar value you want
B = myScalar*ones(size(A))
B = 1×5
2 2 2 2 2

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by