Separate data series based on parameter within the data.

1 vue (au cours des 30 derniers jours)
Theodore
Theodore le 18 Fév 2025
Modifié(e) : Stephen23 le 18 Fév 2025
I have a data series 50704x4 which contains data that looks roughly like this
A = [1,n,n,n;
1,n,n,n;
2,n,n,n;
...
100,n,n,n]
where the n are numerical data and the 1,2,...,100 are the frequency that i logged data for. I want to change this to have a distinct A1, A2, ... for each frequency.
If it is useful, the frequencies used are 1,2,3.3,5,8,10,20,40,50,70,90, and 100
how can i seperate these data?

Réponses (1)

Stephen23
Stephen23 le 18 Fév 2025
Modifié(e) : Stephen23 le 18 Fév 2025
A = [1,12,13,14; 1,21,23,24; 2,32,33,34; 100,42,43,44]
A = 4×4
1 12 13 14 1 21 23 24 2 32 33 34 100 42 43 44
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[G,ID] = findgroups(A(:,1));
Method one:
F = @(x)A(x==A(:,1),:);
C = arrayfun(F,ID,'uni',0)
C = 3x1 cell array
{2x4 double } {[ 2 32 33 34]} {[100 42 43 44]}
C{:}
ans = 2×4
1 12 13 14 1 21 23 24
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 1×4
2 32 33 34
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 1×4
100 42 43 44
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Method two:
F = @(x)A(x==G,:);
C = arrayfun(F,1:max(G),'uni',0)
C = 1x3 cell array
{2x4 double} {[2 32 33 34]} {[100 42 43 44]}
C{:}
ans = 2×4
1 12 13 14 1 21 23 24
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 1×4
2 32 33 34
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 1×4
100 42 43 44
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Method three:
F = @(x){A(x==A(:,1),:)};
V = 1:numel(ID);
C = accumarray(V(:),ID,[],F)
C = 3x1 cell array
{2x4 double } {[ 2 32 33 34]} {[100 42 43 44]}
C{:}
ans = 2×4
1 12 13 14 1 21 23 24
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 1×4
2 32 33 34
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 1×4
100 42 43 44
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Method four:
F = @(x){A(x,:)};
V = 1:size(A,1);
C = splitapply(F,V(:),G)
C = 3x1 cell array
{2x4 double } {[ 2 32 33 34]} {[100 42 43 44]}
C{:}
ans = 2×4
1 12 13 14 1 21 23 24
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 1×4
2 32 33 34
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 1×4
100 42 43 44
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
"how can i seperate these data?"
Note that splitting up data like that is often not required (and is in many cases an inefficient approach to data storage/processing):

Catégories

En savoir plus sur Data Acquisition Toolbox Supported Hardware dans Help Center et File Exchange

Produits


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by