how can i change the dimension of the matrix?

21 ビュー (過去 30 日間)
RADWAN A F ZEYADI
RADWAN A F ZEYADI 2022 年 1 月 8 日
回答済み: Image Analyst 2022 年 1 月 8 日
hi
i have matrix 51 500 3,how can i change it to 153*500
g=51 500 3

回答 (3 件)

Yusuf Suer Erdem
Yusuf Suer Erdem 2022 年 1 月 8 日
Try these codes below but note that x1 matrix is created randomly, you need to adapt it according to your own matrix. Good luck!
clc; clear;
x1 = randi([0, 100], [51,500,3]);
x2 = reshape(x1,[153,500]);

Torsten
Torsten 2022 年 1 月 8 日
You must first decide where you want element (i,j,k) of the old matrix be placed in the new matrix.
But usually MATLAB's "reshape" can help.

Image Analyst
Image Analyst 2022 年 1 月 8 日
Try this:
g2 = [g(:,:,1); g(:,:,2); g(:,:,3)];
The result is 153 rows by 500 columns.
Here's a full demo with a 3-D RGB true color image (though it doesn't have the same number of rows and columns, it's just to show you the order where things are put):
g = randi([0, 100], [51,500,3]);
g2 = [g(:,:,1); g(:,:,2); g(:,:,3)];
% Demo (though with different number of rows and columns).
g = imread('peppers.png');
subplot(1, 2, 1);
imshow(g);
axis('on', 'image');
g2 = [g(:,:,1); g(:,:,2); g(:,:,3)];
subplot(1, 2, 2);
imshow(g2);
axis('on', 'image');

カテゴリ

Find more on Matrices and Arrays 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!

Translated by