フィルターのクリア

change matrix from 3D TO 2D

1 回表示 (過去 30 日間)
abbas hasan
abbas hasan 2012 年 12 月 6 日
コメント済み: Mattias Gothberg 2022 年 5 月 20 日
i have 3d matrix (512x512x3) i want transform to 2d matrix (512x512)
  1 件のコメント
Mattias Gothberg
Mattias Gothberg 2022 年 5 月 20 日
check out squeeze comand after apropiate processing or selection

サインインしてコメントする。

回答 (2 件)

Thomas
Thomas 2012 年 12 月 6 日
編集済み: Thomas 2012 年 12 月 6 日
Your matrix has 512*512*3=786432 elements.. to reshape you need to keep the number of elements the same.. That means you cannot reshape if you want just 512*512 elements without losing elements or data..
However if you want to access only the first dimension of your matrix (a) you use some thing like a(:,:,1)
If your data is an image data and it has the three dimension r,g,b you can covert it to grayscale (using im2bw)which should give you a matrix of 512*512
Example for my color image 1.jpg
ii=imread('1.jpg');
size(ii)
ans =
551.00 1024.00 3.00
out=im2bw(ii); % convert to blackwhite
size(out)
ans =
551.00 1024.00

Wayne King
Wayne King 2012 年 12 月 6 日
編集済み: Wayne King 2012 年 12 月 6 日
You have to select one "page" of the 3D matrix, which one do you want?
X = randn(512,512,3);
Y = X(:,:,1);
Or you can form some function of the 3 pages, not sure what you want. For example:
X = randn(512,512,3);
Y = mean(X,3);

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by