필터 지우기
필터 지우기

Creating 25 x 2 matrix with each row range is 20

조회 수: 4 (최근 30일)
NALLARASU KRISH
NALLARASU KRISH 2024년 2월 28일
댓글: NALLARASU KRISH 2024년 2월 28일
i want to occupy 1 to 500 in a matrix of size 25x2 with range of each row is 20. First row contains [1 20], second row contains [21 40], and so on until last 25th row containing [481 500]. I asked chat GPT. It suggested me the following code. But it did not go well.
% Define the range and matrix size
range = 1:500;
matrix_size = [25, 2];
% Calculate the values for each row
row_values = reshape(range, [], 20)';
% Create the matrix by repeating the row values
matrix = repmat(row_values(:), 1, matrix_size(2));
% Reshape the matrix to the desired size
matrix = reshape(matrix, matrix_size);
% Display the matrix
disp(matrix);
Pls clarify!

채택된 답변

Stephen23
Stephen23 2024년 2월 28일
m = (0:20:499).' + [1,20]
m = 25×2
1 20 21 40 41 60 61 80 81 100 101 120 121 140 141 160 161 180 181 200
  댓글 수: 1
NALLARASU KRISH
NALLARASU KRISH 2024년 2월 28일
Its a magic! Tq!! Pls provide in generalized form to make it universal.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by