Creating a variable that denotes a range of values
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Abinand Rejimon
am 27 Jun. 2022
Kommentiert: Abinand Rejimon
am 27 Jun. 2022
I have a dataset that looks like this:
Signal PT#1 PT#2 ... PT#26
0.20 2121 1232
0.21 1233 1233
0.22 1236 1232
0.23 1232 1236
...
1.00 1212 1232
...
4.00 1212 12321
I used this code to discretize the values to the hundredth's and average it for each group of values.
edges = (0:0.05:4);
allData(:,27) = discretize(allData(:,1),edges);
[C,~,IC] = unique(allData(:,27));
avg=NaN(76,26);
for i = 1:25
avg(:,i) = accumarray(IC, allData(:, i+1), [], @mean); % calculate the mean in your data of column 2 for rows in IC with identical elements
end
Result = [C avg];
This resulted in a dataset "Result" that looks like this
1 1241 1231 1232
2 1232 1232 1231
...
76 2312 1231 1231
How do I convert the first column into ranges of the variables that were discretized? Like I want the first row to say "0.2 to 0.25" rather than "1" ?
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 27 Jun. 2022
x = 4*rand(10, 1);
edges = (0:0.05:4);
y = discretize(x, edges, 'categorical');
results = table(x, y)
Or if you want more control over the format of the category names:
categoryNames = edges(1:end-1) + " to " + edges(2:end);
z = discretize(x, edges, 'categorical', categoryNames);
results2 = table(x, z)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!