How can i write any vector for many time from short form??

1 回表示 (過去 30 日間)
Triveni
Triveni 2016 年 6 月 29 日
コメント済み: Triveni 2016 年 6 月 29 日
i have a vector
V1 = [ 45 -45 45 -45 45 -45 45 -45 45 -45 45 -45 45 -45 45 -45 45 -45];
V2 = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
i want to enter just for 1 time 0 and multiple of 20 and automatically expand. for 45 and -45, just want to enter 45 and -45 and multiple of 9. and new vector v make automatically [V1, V2]; or suggest any program to automatically MATLAB ask to enter any value like 0 or 45 or -45... and how many times, and value how many times want to enter each value? and automatically create new vector
V = [V1, V2....Vn] or V = [V(1), V(2)...V(n)];

採用された回答

KSSV
KSSV 2016 年 6 月 29 日
function V = formvec
a = input('Enter the array to repeat:') ;
N = input('Number of times to repeat:') ;
V = repmat(a,[1 N]);
  1 件のコメント
Triveni
Triveni 2016 年 6 月 29 日
Tell me one thing more
syms formvec
value = [repmat([formvec], [1,11])] %number of required repeatation 1,2...
Convert formvec to variable. which directly run.

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

その他の回答 (1 件)

KSSV
KSSV 2016 年 6 月 29 日
編集済み: KSSV 2016 年 6 月 29 日
K1 = [45 -45] ;
v1 = repmat(K1,[1 9]) ;
K2 = 0 ;
V2 = repmat(K2,[1 20]) ;
V3 = zeros(1,20) ;
doc repmat, zeros,ones etc.
  1 件のコメント
Triveni
Triveni 2016 年 6 月 29 日
Can you tell me program to generate it automatically?
N = input(' No of value to repeat');
generate repmat according to N and automatically ask value and number of value to be combine in v.
v = [repmat([K1],[1 input1]),repmat([K2],[1 input2]),repmat([K3],[1 input3])]

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

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by