help with matrix and how to extract rows

Hi, would like to manipulate this matrix to get 6x6 matrices.
i like to make the first 6 rows to be the new first row, then 7 to 12 to be the second row and then 13to 19 to be the third row and so one. how can i manipulate the, it should look like this :

 Réponse acceptée

Ameer Hamza
Ameer Hamza le 30 Sep 2020
Modifié(e) : Ameer Hamza le 30 Sep 2020
You can use reshape()
reshape(Radiatondamping(1,:), 6, 6).'
the above will convert first column to 6x6 matrix. To convert all columns and combine them in 3D matrix
permute(reshape(Radiatondamping.', 6, 6, []), [2 1 3])

6 commentaires

Jama Ali
Jama Ali le 30 Sep 2020
Hi, when i use that function i get an error saying:
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
thanks for the help.
Ameer Hamza
Ameer Hamza le 30 Sep 2020
Modifié(e) : Ameer Hamza le 30 Sep 2020
Oh! I though 36 elements are in one column. Whereas they are in one row. Try the updated code.
Jama Ali
Jama Ali le 30 Sep 2020
Thanks you, it worked. i really apricaited your help. it was helpfull.
one last question, is there a way i can name the different matrices so i can use them separately?
No need to save in different name. Such coding practice is discouraged: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval. You can create a 3D matrix and access its pages
new_Radiatondamping = permute(reshape(Radiatondamping.', 6, 6, []), [2 1 3])
and access values like this
new_Radiatondamping(:,:,1) % 1st 6x6 matrix
new_Radiatondamping(:,:,2) % 2nd 6x6 matrix
new_Radiatondamping(:,:,3) % 3rd 6x6 matrix
..
..
new_Radiatondamping(:,:,end) % last 6x6 matrix
Jama Ali
Jama Ali le 30 Sep 2020
Thank you for your help. It made my school project much easier.
Ameer Hamza
Ameer Hamza le 1 Oct 2020
I am glad to be of help!

Connectez-vous pour commenter.

Plus de réponses (2)

madhan ravi
madhan ravi le 30 Sep 2020
Wanted = mat2cell(matrix, repelem(6, numel(matrix)/36)) % not tested
celldisp(Wanted)
Image Analyst
Image Analyst le 30 Sep 2020
Modifié(e) : Image Analyst le 30 Sep 2020
Here's one way (tested on made up "data"):
data = randi(99, 12, 6)
[rows, columns] = size(data)
newRows = rows / 6 % This better be an integer!!!
d = data'
Radiatondamping = reshape(d(:), [], newRows)'

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by