MATLAB Answers

create array of arrays from a single array

50 views (last 30 days)
Benjamin
Benjamin on 16 May 2019
Answered: Star Strider on 16 May 2019
I have an array that looks like this:
0.000100000000000000 85 0.710500000000000 -0.118400000000000 0.00136500000000000 1.40700000000000
0.000500000000000000 85 0.710000000000000 -0.118200000000000 0.00136400000000000 1.40800000000000
0.00100000000000000 85 0.709300000000000 -0.118000000000000 0.00136300000000000 1.41000000000000
0.00250000000000000 85 0.707200000000000 -0.117400000000000 0.00135800000000000 1.41400000000000
0.000100000000000000 90 181.400000000000 0.0451000000000000 0.00324000000000000 0.00551300000000000
0.000500000000000000 90 0.726300000000000 -0.113200000000000 0.00142000000000000 1.37700000000000
0.00100000000000000 90 0.725500000000000 -0.113000000000000 0.00141900000000000 1.37800000000000
0.00250000000000000 90 0.723000000000000 -0.112400000000000 0.00141300000000000 1.38300000000000
0.00500000000000000 90 0.719100000000000 -0.111300000000000 0.00140600000000000 1.39100000000000
0.0100000000000000 90 0.711900000000000 -0.109100000000000 0.00139100000000000 1.40500000000000
0.0200000000000000 90 0.699300000000000 -0.104500000000000 0.00136300000000000 1.43000000000000
0.000100000000000000 95 192.400000000000 0.0474000000000000 0.00327100000000000 0.00519800000000000
0.000500000000000000 95 0.743800000000000 -0.108000000000000 0.00147700000000000 1.34400000000000
0.00100000000000000 95 0.742800000000000 -0.107800000000000 0.00147500000000000 1.34600000000000
0.00250000000000000 95 0.739800000000000 -0.107200000000000 0.00147000000000000 1.35200000000000
0.00500000000000000 95 0.735200000000000 -0.106200000000000 0.00146200000000000 1.36000000000000
0.0100000000000000 95 0.726700000000000 -0.104000000000000 0.00144600000000000 1.37600000000000
0.0200000000000000 95 0.712300000000000 -0.0995000000000000 0.00141700000000000 1.40400000000000
0.0300000000000000 95 0.700300000000000 -0.0948000000000000 0.00139200000000000 1.42800000000000
0.0400000000000000 95 0.690000000000000 -0.0900000000000000 0.00137000000000000 1.44900000000000
How do I create an array that holds arrays? Every time the value in column B changes, I want it to be a new array. How can I do this?

Answers (1)

Star Strider
Star Strider on 16 May 2019
If ‘A’ is your matrix:
A = [0.0001 85.0000 0.7105 -0.1184 0.0014 1.4070
0.0005 85.0000 0.7100 -0.1182 0.0014 1.4080
0.0010 85.0000 0.7093 -0.1180 0.0014 1.4100
. . . ];
[Uid,~,idx] = unique(A(:,2)); % Unique ID Values
C = accumarray(idx,[1:size(A,1)]',[],@(x){A(x,:)}); % Submatrices
produces:
C1 = [C{1}]
C2 = [C{2}]
C1 =
0.0001 85.0000 0.7105 -0.1184 0.0014 1.4070
0.0005 85.0000 0.7100 -0.1182 0.0014 1.4080
0.0010 85.0000 0.7093 -0.1180 0.0014 1.4100
0.0025 85.0000 0.7072 -0.1174 0.0014 1.4140
C2 =
0.0001 90.0000 181.4000 0.0451 0.0032 0.0055
0.0005 90.0000 0.7263 -0.1132 0.0014 1.3770
0.0010 90.0000 0.7255 -0.1130 0.0014 1.3780
0.0025 90.0000 0.7230 -0.1124 0.0014 1.3830
0.0050 90.0000 0.7191 -0.1113 0.0014 1.3910
0.0100 90.0000 0.7119 -0.1091 0.0014 1.4050
0.0200 90.0000 0.6993 -0.1045 0.0014 1.4300
and so for the rest.

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by