make single element be array,,

73 views (last 30 days)
baby
baby on 12 May 2012
hello,,
i m new beginner in matlab,,
so i still have little experience,,
i want to ask about how to make single element be array,,
example i have variable called w1 = 1;
and i want make array of w1 like w1 = [1 1 1 1 1]
please help me,,

Accepted Answer

per isakson
per isakson on 12 May 2012
This used to be called Tonys trick:
w1 = w1( ones( 1, 5 ) );
this is more standard
w1 = repmat( w1, 1, 5 );
PS. There is a good Getting Started!
--- Edit ---
>> w1=-0.5
w1 =
-0.5000
>> w1( ones( 1, 5 ) )
ans =
-0.5000 -0.5000 -0.5000 -0.5000 -0.5000
You need to experiment!
>> repmat( -0.11, 1, 5 )
ans =
-0.1100 -0.1100 -0.1100 -0.1100 -0.1100

More Answers (1)

baby
baby on 12 May 2012
But how if i want convert another number like w1 = -0.5 be w1 = [-0.5 -0.5 -0.5 -0.5 -0.5]?

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!