Find the exact multiple of a number by zero padding values.
Afficher commentaires plus anciens
Say
A = 13848 x 1
and I want to reshape into a 173(matters a lot) by 80 or 81(this doesn't matter) but that isn't possible as 13848 isn't divible by 173.
So I want a way where it reads A and calculates the next perfect value which is 14013 by zero padding A.
I could just remove 8 from A but I don't loose data but I don't mind zero padding to A towards the end.
1 commentaire
CalebJones
le 5 Fév 2020
Modifié(e) : CalebJones
le 5 Fév 2020
Réponse acceptée
Plus de réponses (1)
A = rand(13848,1) ;
n = length(A) ; % length of A
r = 80 ; % to reshape by this dimension
N = mod(-mod(n,r),r); % get the number of zeros to be appended
A = [A ; zeros(N,1)] ; % append zeros
iwant = reshape(A,r,[]) ; % reshape
2 commentaires
Stephen23
le 5 Fév 2020
getting an error.
n = size(right_pc,1) ; % length of A
r = 80; % to reshape by this dimension
N = mod(-mod(n,r),r); % get the number of zeros to be appended
A = [right_pc(:,1) ; zeros(N,1)] ; % append zeros
iwant = reshape(A,r,[]) ; % reshape
when i tried to run...this
N = mod(-mod(n,r),r);
Index in position 1 exceeds array bounds (must not exceed 173).
I have atteched a mat file as well.
Stephen23
le 5 Fév 2020
You have created a variable named mod. Clear that variable from the workspace.
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!