REad about table2array
Convert table into 2D matrix
6 次查看(过去 30 天)
显示 更早的评论
I want to do data 2D binning of a variable "signal" by 2 other variables 'speed' and 'direction'
a1=0;
b1=360;
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'})
binAvg = groupsummary(data, ["DirBinIdx", "SpeedBinIdx"], "mean","Signal")
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'
0 个评论
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!