Filter löschen
Filter löschen

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

128 Ansichten (letzte 30 Tage)
Bennett Torrance
Bennett Torrance am 22 Mär. 2017
Kommentiert: dpb am 23 Mär. 2017
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 Kommentar
Bennett Torrance
Bennett Torrance am 22 Mär. 2017
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...

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

dpb
dpb am 22 Mär. 2017
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 Kommentare
Bennett Torrance
Bennett Torrance am 23 Mär. 2017
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 am 23 Mär. 2017
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by