필터 지우기
필터 지우기

make vectors same length

조회 수: 3 (최근 30일)
Adam Levschuk
Adam Levschuk 2020년 8월 6일
댓글: Matt J 2020년 8월 7일
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일
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월 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일
Maybe this:
lastRow = min([length(acc), length(gyr), length(mag)])
% Crop
acc = acc(1 : lastRow);
gyr = gyr(1 : lastRow);
mag = mag(1 : lastRow);

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by