Create Surface Averages from Mesh Node Data Values
5 次查看(过去 30 天)
显示 更早的评论
Hi,
I've created a mesh geometry and exported (x,y,z, value) data corresponding to each node on the mesh. There are about 39,240 x 4 rows of data in this format.
The goal is to produce surface averages by use of surface integrals, for each z value, which corresponds to depth here. This is visualised by creating a graph that plots the values of surface averages with respect to depth, and is expected to be an exponential decay.
I have approached this by trying to group all of the unique z values into a "doubles" within a "cell", and then unpack each one in a for loop and create a table of surface averages with respect to depth.
This is the very basic code I have so far:
A = readtable('S4MeshData.txt');
A = table2array(A);
A = round(A,5);
%This groups the data set into unique values of z
[~,~,gId] = unique( A(:,3), 'rows' );
groups = splitapply( @(x){x}, A, gId );
%Beginning of what will be the loop to unpack each of the "doubles" and
%find the surface average (uncompleted - doesn't work)
for i = 1:516
node(i) = groups{i};
node(i)(:,3) = [];
x(i) = node(i)(:,1)
y(i)= node(i)(:,2);
var(i) = node(i)(:,3);
%Use these values to create surface averages.
end
My questions are:
Q1: How can I extract the (x,y,z,value) data for each unique value of z, and use z as a sort of label for each of these datasets to later use in the plot?
Q2: How is a surface average calculated on MATLAB from just the (x,y,value) data using surface integrals? Is there a specific function for this?
Q3: Is there a way to round just the 'z' values from the data at the start, instead of also rounding the value data as well
MeshData file is attached.
Thanks in advance for any help!
- Felix
0 个评论
回答(1 个)
Githin George
2023-11-12
Hello,
My understanding is that you would like to round the values in column ‘z’, obtain the unique values in ‘z’ and then calculate surface average the same.
Rounding of the ‘z’ values and preparing the data using unique values in ‘z’ can be done using the following code.
A = readtable('S4MeshData.txt');
A = table2array(A);
% Round only the 'z' values
A(:, 3) = round(A(:, 3));
% Find unique 'z' values and their corresponding indices
[uniqueZ, ~, zIndices] = unique(A(:, 3));
% Initialize cell arrays to store data for each unique 'z' value
xData = cell(size(uniqueZ));
yData = cell(size(uniqueZ));
valueData = cell(size(uniqueZ));
% Iterate over each unique 'z' value
for i = 1:numel(uniqueZ)
% Find the indices corresponding to the current 'z' value
indices = find(zIndices == i);
% Extract the (x, y, value) data for the current 'z' value
xData{i} = A(indices, 1);
yData{i} = A(indices, 2);
valueData{i} = A(indices, 4);
end
For obtaining the surface average, you would need to compute surface area and surface integral and divide them.
The “trapz” function in MATLAB can be used to obtain the surface integrals. Please refer to the link below to know more about “trapz” function.
To calculate the surface-area, you could refer to the following MATLAB answers link.
I hope this helps.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!