MATLAB Answers

0

Iterate between fixed numbers in an array and store into a matrix.

Asked by Saji Kamdod on 28 Oct 2019
Latest activity Edited by Stephan
on 28 Oct 2019
I'm trying to iterate an array for the first 250 element and store certain values like the max, min, mean and peak2peak in a array. I first want to iterate the 250 elements out of an array of 98000 and store these values in a different array and then continue from 251st element until it reaches 98000.

  0 Comments

Sign in to comment.

Products


Release

R2019b

1 Answer

Answer by Stephan
on 28 Oct 2019
Edited by Stephan
on 28 Oct 2019

I suggest to reshape the array to have 250 rows. The most Matlab functions like mean, max, min, sum... work on the columns of an array by default, so this is easy to write. For example:
A = randi(100,10,5)
A_mean = mean(A)
A_max = max(A)
A_min = min(A)
A =
37 51 88 23 44
63 52 56 18 12
79 82 63 23 26
9 80 59 44 41
93 65 21 32 60
78 38 31 93 27
49 82 48 44 61
44 54 24 19 72
45 36 85 91 23
31 94 20 98 12
A_mean =
52.8000 63.4000 49.5000 48.5000 37.8000
A_max =
93 94 88 98 72
A_min =
9 36 20 18 12
To reshape use:
A = reshape(YourArrayName,250,[]);
Writing them all in one array would work this way:
A_properties(1,:) = mean(A);
A_properties(2,:) = max(A);
A_properties(3,:) = min(A);

  0 Comments

Sign in to comment.