Matrix into Sub matrix of length 8
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hamza Naeem
le 5 Mai 2019
Commenté : Hamza Naeem
le 9 Mai 2019
Suppose I have a matrix like this A = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24] (Length of a Matrix is always multiple of 8). I want to break it into sub matrices of length 8. I use reshape function but it does not work. Needs your help.
1 commentaire
dpb
le 5 Mai 2019
What does "does not work" mean, precisely? Show your work, error received...or what you expected instead.
In general breaking into submatrices by creating new variables isn't productive manner in which to use, Matlab; instead reference subsets of an array as needed for which reshape can be quite useful...or, depending on what it is that is actually being done, blockproc in the image processing toolbox can be the ticket or various other specialty routines can be the answer--each depending on just what the actual end need may be...
Réponse acceptée
Image Analyst
le 5 Mai 2019
What did you try for reshape? Did you try reshape(A, [], 8)?
A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24];
a8 = reshape(A, [], 8)
% For example, to get 2nd subarray of 8 specify group as 1st index and : as second index.
out = a8(2,:)
Plus de réponses (1)
KALYAN ACHARJYA
le 5 Mai 2019
Modifié(e) : madhan ravi
le 5 Mai 2019
A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24];
n=length(A)/8;
C=num2cell(reshape(A,length(A)/n,n),1);
Access the subarrays in C{1}, C(2)..so on..
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!