Convert table into 2D matrix

I want to do data 2D binning of a variable "signal" by 2 other variables 'speed' and 'direction'
a1=0;
b1=360;
N=100;
N = 100
direction = a1 + (b1-a1).*rand(N,1);
a2=1;
b2=16;
speed = a2 + (b2-a2).*rand(N,1);
a3=-5;
b3=5;
signal = a3 + (b3-a3).*rand(N,1);
ndirections = 36;
dirBins = linspace(0,360,ndirections+1); %wind direction bins of 10deg
vmax = ceil(max(speed));
windBins = linspace(1,vmax,vmax);
[Yspd,Espd] = discretize(speed,windBins);%bins index of wind speed
[Ydir,Edir] = discretize(direction,dirBins);%bins index of wind direction
data = array2table([direction, speed,Ydir, Yspd,signal], 'VariableNames', {'Direction', 'Speed','DirBinIdx','SpeedBinIdx', 'Signal'})
data = 100×5 table
Direction Speed DirBinIdx SpeedBinIdx Signal _________ ______ _________ ___________ ________ 6.7114 7.7659 1 7 -4.5375 267.9 7.5038 27 7 0.50178 64.713 8.929 7 8 2.3849 192.98 4.0114 20 4 -4.3776 19.68 13.746 2 13 -0.51325 128.41 5.5993 13 5 -1.7249 316.3 12.593 32 12 3.3347 322.43 8.2344 33 8 -4.1392 244.95 8.3105 25 8 0.16218 184.3 15.197 19 15 -2.2387 273.64 1.4889 28 1 -2.952 333.49 6.263 34 6 -0.30713 120.49 5.5329 13 5 3.6812 85.721 15.615 9 15 3.2914 329.52 5.7136 33 5 -3.4584 264.41 1.2378 27 1 -4.7495
binAvg = groupsummary(data, ["DirBinIdx", "SpeedBinIdx"], "mean","Signal")
binAvg = 95×4 table
DirBinIdx SpeedBinIdx GroupCount mean_Signal _________ ___________ __________ ___________ 1 7 1 -4.5375 1 11 1 -0.23016 1 13 1 1.4332 2 3 1 -1.5489 2 13 1 -0.51325 3 14 1 -0.34484 3 15 1 0.61782 4 1 1 3.5306 4 12 1 1.3497 5 7 1 -0.9348 7 6 1 -4.5022 7 8 1 2.3849 8 1 1 1.4526 8 8 1 1.3615 8 11 1 1.9656 8 15 1 1.697
Given binAvg, I would like to convert it in a matrix with columns from "DirBinIdx", rows from "SpeedBinIdx" and the values of the matrix given by 'Signal'

类别

帮助中心File Exchange 中查找有关 Tables 的更多信息

标签

提问:

2022-11-21

回答:

2022-11-21

Community Treasure Hunt

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

Start Hunting!

Translated by