How to add a constant value above a matrix in following code?
2 次查看(过去 30 天)
显示 更早的评论
Hello
P is a matrix of 100 106 and I am trying to add 20 constant values (say 0.25) above each row and 20 constant values (say 0.21) below each rows to make P as 140 106. How I can change following code? instead of taking first value of each column (P(1,:)), how I can replace with a constant value?
A_pad = zeros(140,106);
A_pad(1:20,:) = ones(20,1)*P(1,:);
A_pad(21:120,:) = P;
A_pad(121:140,:) = ones(20,1)*P(end,:);
0 个评论
采纳的回答
更多回答(1 个)
Steven Lord
2022-11-7
A = magic(4)
B = [repmat(-999, 2, width(A));
A;
repmat(Inf, 3, width(A))]
This pads 2 rows containing the constant -999 above the matrix A and 3 rows containing the constant Inf below.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!