To obtain the average 'B' value by using Theta value according to each R value in the 3960x4 Matrix

1 次查看(过去 30 天)
Dear colleagues,
I am trying to calculate a B value. I have a 3960x4 matrix. In this matrix, R value is the first column, Theta value is the second column and Bz value is the fourth column. (No need for the third column.)
My purpose is to find the average of the B values in all Theta values for each R value. I will draw the graph (43x2) of B according to the R values.
Example:
For R=2,
B(Theta_0(R=2)) + B(Theta_1(R=2)) + B(Theta_2(R=2)) + ... + B(Theta_89(R=2))= Avg(B(R=2))
Many thanks

采纳的回答

Berat Can Karatas
Berat Can Karatas 2020-7-22
编辑:Berat Can Karatas 2020-7-22
I found solution by myself.
Here is the code without loop.
X=readtable('rt_v1.txt');
R(:,1)=X{:,1}/100;%radius (m)
R(:,2)=X{:,4}*0.0001; %magnetic field (Tesla)
A=sortrows(R,1); %sorting according to R value
[r,c] = size(A);
nlay = 42; % layer size
Avg = transpose(squeeze(mean(permute(reshape(A',[c,r/nlay,nlay]),[2,1,3]),1)))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by