how to create this vector [ 10 9 10 9 ...] with one command

hi can you help us to create this vector with one command v=[10 9 10 9 ...] 100 times with one command only
and how to create this vector =[ 1 1 2 2 3 3 4 4] with only one command !!
also how to create this with only one command =[ 1 1 2 2 1 1 2 2]
and finally this vector =[ -1 1 -2 2 -3 3 -4 4]
thank you guys :-) !!

2 件のコメント

Jan
Jan 2013 年 4 月 15 日
What does "one command" exactly mean? Please not that for "v = [10, 9]" you call subsasgn and horzcat already.
We do not solve homework questions, but we like to assist you to solve them by your own. Please post, what you have tried so far and explain the occurring problems.
Malak
Malak 2013 年 4 月 15 日
Its not a homework im studying for a final exam and im trying every possible way to create these kinds of vectors I tried these functions ..... repmat and for example a=zeros(1,100) >> a(1:2:99)=10 a(2:2:100)=8 a.*-1.*(-1).^[1:100] to get 10 -8 10 -8 ..and so on

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

 採用された回答

Youssef  Khmou
Youssef Khmou 2013 年 4 月 15 日
編集済み: Youssef Khmou 2013 年 4 月 15 日

0 投票

hi, try :
v=repmat([10 9]',[50 1]);

2 件のコメント

Malak
Malak 2013 年 4 月 15 日
Do you know how to repeat two different numbers like 11 22 or repeat four different numbers
Youssef  Khmou
Youssef Khmou 2013 年 4 月 15 日
same way : repmat([1 2 3 4]',[4 1]) % 4 times

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

その他の回答 (1 件)

Jan
Jan 2013 年 4 月 15 日
編集済み: Image Analyst 2013 年 4 月 15 日

0 投票

Never forget the really obvious solution:
v = [10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, ...
10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, ...
10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, ...
10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, ...
10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, ...
10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, ...
10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, ...
10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, ...
10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, ...
10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9];
w = [ 1 1 2 2 3 3 4 4]
x = [ 1 1 2 2 1 1 2 2]
y = [ -1 1 -2 2 -3 3 -4 4]
There are less efficient solutions based on the commands repmat or kron.

2 件のコメント

Malak
Malak 2013 年 4 月 15 日
編集済み: Image Analyst 2013 年 4 月 15 日
I know the obvious solution, but I can't use it in the final
Jan
Jan 2013 年 4 月 15 日
Then, Malak, please explain this in your question. It is not a good idea to expect, that the readers can guess, what you need.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by