Why is operator = is clever sometimes but not always?
Show older comments
M = zeros(N,6);
M(:,1) = ones(N,1); % OK
M(:,2) = ones(1,N); % OK
M(:,[3,4]) = zeros(N,2); % OK
M(:,[5,6]) = zeros(2,N); % ERROR
Answers (2)
Image Analyst
on 16 Jun 2015
1 vote
And why shouldn't it give an error? You're trying to stuff a 2 row by N column matrix into an N row by 2 column space. The sizes of the rows and columns don't match up. You can't stuff a n-by-m matrix into an j-by-k space unless n equals j and m equals k (unless the matrix is a 1D vector).
Walter Roberson
on 16 Jun 2015
1 vote
Vectors are treated differently as a convenience because most of the time row vector vs column vector is irrelevant to people.
Categories
Find more on Operators and Elementary Operations 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!