필터 지우기
필터 지우기

Convert matrix size from 1xmxn to mxn

조회 수: 56 (최근 30일)
Kris zenitis
Kris zenitis 2014년 7월 2일
편집: Erik Kruit 2020년 10월 13일
I want to compare two matrices. One's size is mxn and the other matrix size 1xmxn. How can I convert 1xmxn to mxn??

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 7월 2일
편집: Andrei Bobrov 2014년 7월 2일
Z = randi(250,1,3,4); % your matrix
one way
out = squeeze(Z)';
other
out = permute(Z,[3 2 1]);
or
out = reshape(Z,size(Z,2),[])';
  댓글 수: 1
Erik Kruit
Erik Kruit 2020년 10월 13일
편집: Erik Kruit 2020년 10월 13일
Googled really long on this! Thanks!
size(A)=1xMxN matrix. Unable to then imagsc(A(jpos,:,:))
error(using image Color data must be an m-by-n-by-3 or m-by-n matrix.)
Solved by:
Qi=squeeze(A(jpos,:,:));
imagesc(Qi);
% Squeeze used to convert the resulting 1xMxN matrix into a MxN matrix

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

추가 답변 (1개)

Piyush kant
Piyush kant 2019년 4월 9일
Just adding some context to previous answer by Andrei Bobrov. Basic idea is to convert 1 x m x n matrix into m x n x 1 as matlab omits last dimension if it is 1. Therefore the method i prefer is:
NewMat=sqeeze(Z)';
Whereas other two functions does the same thing.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by