Creating a variable that denotes a range of values
조회 수: 20 (최근 30일)
이전 댓글 표시
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
채택된 답변
Steven Lord
2022년 6월 27일
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!