Why i cannot copy elements of matrix a(1X10) into b(2X5) matrix?

2 views (last 30 days)
a
a =
1 2 3 4 5 6 7 8 9 10
>> b
b =
0 0 0 0 0
0 0 0 0 0
>> b(1,:)=a(0:4) ??? Subscript indices must either be real positive integers or logicals.

Answers (1)

Jan
Jan on 22 Jul 2011
The error message is descriptive:
Subscript indices must either be real positive integers or logicals.
Using "0:4" is not "positive", because Matlab's indexing is 1-based:
b(1, :) = a(1:5)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!