フィルターのクリア

find center of matrix

48 ビュー (過去 30 日間)
arame sotudegan
arame sotudegan 2021 年 3 月 3 日
移動済み: Image Analyst 2023 年 6 月 4 日
Hello everyone. I have a 100*120 Matrix and I want to find a mini square insite the matrix exactly at its center. How can I find it?

採用された回答

jessupj
jessupj 2021 年 3 月 3 日
移動済み: Image Analyst 2023 年 6 月 4 日
A( 49: 51, 59:61) for a 2x2 submatrix.

その他の回答 (1 件)

Kautuk Raj
Kautuk Raj 2023 年 6 月 3 日
To find a mini square exactly at the center of a 100x120 matrix in MATLAB, we can follow the following steps:
  1. Calculate the center coordinates of the matrix using the size function.
  2. Define the size of the mini square you want to extract.
  3. Calculate the starting row and column indices of the mini square.
  4. Extract the mini square using the calculated row and column indices.
This is the MATLAB code for doing this:
% Define the matrix
matrix = rand(100, 120);
% Calculate the center coordinates of the matrix
[rows, cols] = size(matrix);
center_row = ceil(rows/2);
center_col = ceil(cols/2);
% Define the size of the mini square
square_size = 10;
% Calculate the starting row and column indices of the mini square
start_row = center_row - floor(square_size/2);
start_col = center_col - floor(square_size/2);
% Extract the mini square
mini_square = matrix(start_row:start_row+square_size-1, start_col:start_col+square_size-1);
The resulting mini square will be a 10x10 matrix in the center of the original matrix. The code can be run to find the mini square.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by