Effacer les filtres
Effacer les filtres

make vectors same length

3 vues (au cours des 30 derniers jours)
Adam Levschuk
Adam Levschuk le 6 Août 2020
Commenté : Matt J le 7 Août 2020
Hello,
I input my data as three different variables, acc, gyr, and mag. I want a small amount of code that makes all three variables the length of the shortest variable.
For example, if acc is 12000x1 and gyr is 12000x1, but mag is 12001x1, how can i automate deleting this row to make the vectors all the same length.
Thank you for your help,
Adam

Réponse acceptée

Matt J
Matt J le 6 Août 2020
Modifié(e) : Matt J le 6 Août 2020
One way,
collection = {acc,gyr,mag};
minlen = min(cellfun('length',collection));
clipped=cellfun(@(z)z(1:minlen),collection,'uni',0);
[acc,gyr,mag]=deal(clipped{:})
  5 commentaires
Adam Levschuk
Adam Levschuk le 7 Août 2020
thanks matt
Matt J
Matt J le 7 Août 2020
but note that,
>> isvector(rand(12000,3))
ans =
logical
0

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 7 Août 2020
Maybe this:
lastRow = min([length(acc), length(gyr), length(mag)])
% Crop
acc = acc(1 : lastRow);
gyr = gyr(1 : lastRow);
mag = mag(1 : lastRow);

Catégories

En savoir plus sur Programmatic Model Editing dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by