フィルターのクリア

How do I cut down the size of an array of data?

128 ビュー (過去 30 日間)
Bennett Torrance
Bennett Torrance 2017 年 3 月 22 日
コメント済み: dpb 2017 年 3 月 23 日
I have a few arrays, with one column each, of different sizes (200127, 200126, 200120, etc.) In order to preform the calculations I want to do, I need them to all be the same length. Is there a way to cut them all down to the smallest array I have?
  1 件のコメント
Bennett Torrance
Bennett Torrance 2017 年 3 月 22 日
I figured out a (possibly inefficient) way of doing it by using the line:
Flow([200121 200122 200123 200124 200125 200126 200127], :) = [];
where flow is the name of the array and I'm using the line to take off the last 7 data points in order to get it down to my smallest array.
There's got to be a better way to do this tho...

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

採用された回答

dpb
dpb 2017 年 3 月 22 日
It'd be easier if there weren't different variables, but since they're inconsistent in length that makes it a little more of a pain unless you were to initially use a cell array where each cell column contained one of these arrays.
But, the syntax you're looking for to do the size reduction is
[mn,imn]=min(length(A),length(B),...,length(Z)); % minimum length of all your arrays and which one
A(N+1:end)=[];
B(N+1:end)=[];
C(N+1:end)=[];
... % you get the picture, excepting, of course for whichever variable it is that corresponds to variable imn
Alternatively, you can save instead of cull...
A=A(1:N);
B=B(1:N);
C=C(1:N);
...
this way you don't need to worry about which doesn't have >N elements.
Of course, going on into the problem, you'll undoubtedly want to end up with
Data=[A(1:N) B(1:N) C(1:N) ... Z(1:N)];
so you can now programmatically address all by simply using subscripting expressions instead of having superfluous variables to deal with.
How were these arrays created in the first place? Quite possibly you could have solved all the issues while reading them or some other way before got into this fix.
  4 件のコメント
Bennett Torrance
Bennett Torrance 2017 年 3 月 23 日
They are .dat files converted into matlab files with thousands of data points. And I just do analysis I don't collect data so not really my say...
dpb
dpb 2017 年 3 月 23 日
I'm talking about how to do the analysis more effectively than writing a zillion individual variables that leaves you in the quandary you're currently in, given the data as you've been given it.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by