How to Change only certain Values in a matrix with a different vector?
1 view (last 30 days)
Show older comments
Nicholas Carreon
on 28 Aug 2020
Edited: Bruno Luong
on 28 Aug 2020
So I have a 1x3 vector A and i have matrix B which is 100x3. How do I get the the rows 1:20 to be vector A?
ex:
A = [10 -10 0];
B = zeros(100,3);
B(1:20,:) = A
and then I get the error "Unable to perform assignment because the size of the left side is 100-by-3 and the size of the right side is 1-by-3."
How do I fix this error? I would also rather not use a for loop in this instance.
0 Comments
Accepted Answer
Bruno Luong
on 28 Aug 2020
Edited: Bruno Luong
on 28 Aug 2020
B(1:20,:) = repmat(A,[20 1])
or
B(1:20,:) = repmat(A,20,1)
or
B(1:20,:) = repelem(A,20,1)
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical 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!