Reorganise data in structure cells according to a set of requirements

2 views (last 30 days)
Hello, I was wondering if anyone would know how to reorganize the data I have in the attached data matrix so that it creates in a matrix of cells called SOL (for example) a structure so that:
  • The elements of each component of the cell are those that have the same value for column 4 (the original matrix is already sorted)
  • The SOL{1}.H component is the value of that column and the SOL{1}.data component is the matrix of 5 columns and as many rows as there are rows with the H value in the fourth column.
For examplo for the data.mat file, the first cell should be:
SOL{1}.H = 0;
SOL{1}.data = [1,0.160000000000000,0.130000000000000,0,0.760000000000000;
2,0.820000000000000,0.920000000000000,0,0.530000000000000;
3,0.630000000000000,0.210000000000000,0,0.920000000000000;
4,0.500000000000000,0.0400000000000000,0,0.390000000000000;
5,0.800000000000000,0.920000000000000,0,0.310000000000000;
6,0.140000000000000,0.0600000000000000,0,0.630000000000000;
7,0.690000000000000,0.0100000000000000,0,0.540000000000000;
8,0.790000000000000,0.0700000000000000,0,0.510000000000000;
9,0.660000000000000,0.780000000000000,0,0.800000000000000;
10,0.840000000000000,0.0900000000000000,0,0.0400000000000000;
11,0.590000000000000,0.0500000000000000,0,0.940000000000000;
12,0.0100000000000000,0.430000000000000,0,0.930000000000000;
13,0.640000000000000,0.530000000000000,0,0.980000000000000;
14,0.0100000000000000,0.380000000000000,0,0.610000000000000;
15,0.620000000000000,0.0500000000000000,0,0.860000000000000;
16,0.350000000000000,0.550000000000000,0,0.950000000000000;
17,0.120000000000000,0.450000000000000,0,0.290000000000000;
18,0.290000000000000,0.370000000000000,0,0.170000000000000;
19,0.630000000000000,0.630000000000000,0,0.240000000000000;
20,0.860000000000000,0.0500000000000000,0,0.290000000000000;
21,0.110000000000000,0.520000000000000,0,0.210000000000000;
22,0.580000000000000,0.690000000000000,0,0.640000000000000;
23,0.780000000000000,0.970000000000000,0,0.170000000000000;
24,0.780000000000000,0.380000000000000,0,0.600000000000000;
25,0.290000000000000,0.330000000000000,0,0.220000000000000;
26,0.0900000000000000,0.780000000000000,0,0.190000000000000;
27,0.820000000000000,0.280000000000000,0,0.560000000000000;
28,0.160000000000000,0.180000000000000,0,0.550000000000000;
29,0.620000000000000,0.730000000000000,0,0.720000000000000;
30,0.260000000000000,0.0200000000000000,0,0.850000000000000;
31,0.120000000000000,0.380000000000000,0,0.500000000000000;
32,0.180000000000000,0.380000000000000,0,0.960000000000000;
33,0.550000000000000,0.610000000000000,0,0.860000000000000;
34,0.350000000000000,0.370000000000000,0,0.610000000000000;
35,0.390000000000000,0.280000000000000,0,0.730000000000000;
36,0.330000000000000,0.800000000000000,0,0.290000000000000;
37,0.260000000000000,0.830000000000000,0,0.180000000000000;
38,0.960000000000000,0.0700000000000000,0,0.630000000000000;
39,0.650000000000000,0.500000000000000,0,0.880000000000000;
40,0.570000000000000,0.730000000000000,0,0.840000000000000;
41,0.0700000000000000,0.340000000000000,0,0.210000000000000;
42,0.710000000000000,0.0300000000000000,0,0.120000000000000;
43,0.300000000000000,0.800000000000000,0,0.190000000000000;
44,0.610000000000000,0.690000000000000,0,0.180000000000000;
45,0.100000000000000,0.560000000000000,0,0.180000000000000;
46,0.870000000000000,0.760000000000000,0,0.470000000000000;
47,0.480000000000000,0.900000000000000,0,0.590000000000000;
48,0.570000000000000,0.920000000000000,0,0.0200000000000000;
49,0.330000000000000,0.450000000000000,0,0.0100000000000000;
50,0.850000000000000,0.130000000000000,0,0.680000000000000;
51,0.780000000000000,0.480000000000000,0,0.0900000000000000]
Thank you so much for all

Accepted Answer

Alejandro Fernández
Alejandro Fernández on 17 Nov 2020
Edited: Alejandro Fernández on 17 Nov 2020
Thanks for everything but finally I knew how to solve it.
B = unique(data(:,4));
SOL = cell(length(B),1);
for i = 1 : length(B)
SOL{i}.H = B(i);
SOL{i}.data = data(data(:,4)==B(i),:);
end

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!