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

 採用された回答

Matt J
Matt J 2020 年 8 月 6 日
編集済み: Matt J 2020 年 8 月 6 日

1 投票

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 件のコメント

Adam Levschuk
Adam Levschuk 2020 年 8 月 6 日
HI matt thanks for the help, if acc was a 12000x3 vector, gyr is 12000x3 vector, and mag is a 12001x3 vector, how would this change the code?
Adam
Adam Levschuk
Adam Levschuk 2020 年 8 月 6 日
other than that and the vectors getting transosed it works. Any idea how to make this to handel the 12000x3 and 12001x3 vectors?
Matt J
Matt J 2020 年 8 月 7 日
Like so,
collection = {acc,gyr,mag};
minlen = min(cellfun(@(z)size(z,1),collection));
clipped=cellfun(@(z)z(1:minlen,:),collection,'uni',0);
[acc,gyr,mag]=deal(clipped{:})
Adam Levschuk
Adam Levschuk 2020 年 8 月 7 日
thanks matt
Matt J
Matt J 2020 年 8 月 7 日
but note that,
>> isvector(rand(12000,3))
ans =
logical
0

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 8 月 7 日

1 投票

Maybe this:
lastRow = min([length(acc), length(gyr), length(mag)])
% Crop
acc = acc(1 : lastRow);
gyr = gyr(1 : lastRow);
mag = mag(1 : lastRow);

カテゴリ

製品

リリース

R2020a

質問済み:

2020 年 8 月 6 日

コメント済み:

2020 年 8 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by