I wan to create a 3x3 matrix and this matrix needs to contains first 3 raws and last 3 columns of other matrix which is unknown.
1 次查看(过去 30 天)
显示 更早的评论
I wan to create a 3x3 matrix and this matrix needs to contains first 3 raws and last 3 columns of other matrix which is unknown. How can i do that ? Can you help me about it ?
0 个评论
回答(1 个)
Mitchell Thurston
2021-10-13
With the original larger matrix you want the rows and columns from being "A" and the resulting 3x3 being "B",
A = B(1:3, ... % to specify first 3 rows
end-2:end); % to specify last 3 columns
Since I'm assuming you want this to be a function, and B could be anything (including a matrix less than 3x3, it would be a good idea to have an error check.
function A = first3last3(B)
m,n = size(B);
if (m<3) || (n<3)
error('Input matrix is improper size');
end
A = B(1:3, n-2:n);
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!