I have a matrix of size 9*10. I want each row of the matrix get converted into a 2D matrix, like 3*3 and the coloumns which represent the number of observations, which are 10. At the end I want a 3D matrix, comprising 3*3 matrix, which will represent my data points for a particilar observation and the other dimention in coloumns should be of 10, representing the number of obsverations.

 채택된 답변

Walter Roberson
Walter Roberson 2021년 11월 10일

0 개 추천

Array3D = reshape(Array2D, 3, 3, []);

댓글 수: 5

Badavath Purnesh Singh
Badavath Purnesh Singh 2021년 11월 10일
Thank you so much!!!!
Badavath Purnesh Singh
Badavath Purnesh Singh 2021년 11월 10일
@Walter Roberson I have just tried the method, it seems the 3*3 matrix which Im getting is by the elements whivh are in coloumn, not the elements which are in row. If you have any other possible methods please illstruate or if the previous method works can you point out possibly where I can commit a mistake.
You have a 9 x 10 matrix. There are 9 rows with 10 elements in each row. You want to create a 3 x 3 from those 10 elements. That would leave you with one left over. And since you said that the columns represent the number of observations, it does not make sense to form the 3 x 3 matrix from across the different observations.
Perhaps what you need instead is
Array3D = permute(reshape(Array2D, 3, 3, []), [2 1 3]);
Badavath Purnesh Singh
Badavath Purnesh Singh 2021년 11월 11일
@Walter Roberson Im so sorry, I have failed to convey the problem clearly. I have a matrix of 10*9 matrix, in which each row has 9 elements and each row represents one observation. So basically i need my elements(9) in each row to be a 2D matrix of 3*3. I hope I have explained clearly. I'll try the above mentioned line of code by you. if the problem isnt solved, ill reach out to you. Thank you so much.
Thank you so much for pointing out my mistake in explanning my issue.
Array3D = permute(reshape(Array2D, [], 3, 3), [3 2 1]);

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by