필터 지우기
필터 지우기

Reduce rows of data based on increment size

조회 수: 8 (최근 30일)
Brian Robinson
Brian Robinson 2020년 9월 19일
댓글: Ameer Hamza 2020년 9월 20일
I have a set of data with the depth, z (m) 0 until the maximum length. At the moment there is a total of 951 rows due to the small increment size of z. For analysis purposes, I only require the increment size to be 0.25 m.
So basically what I want to do is the following (pseudocode)
  • Import the excel file into matlab.
  • inc_size = 0.25
  • Iterating through the rows, deltaZ_total = deltaZ(i)
  • While deltaZ_total < (inc_size)
  • deltaZ_total = deltaZ_total + deltaZ(i+1) % while the total of the increments is less than inc_size add them together
  • Create a new row containing deltaZ_total and delete all the previous rows
  • Skip a row % skip a row so the new increments are not being added to the previous
  • Repeat the process until the end of the column
Could I please have some help translating this idea into matlab code.
Thanks very much,
Brian
  댓글 수: 4
Image Analyst
Image Analyst 2020년 9월 19일
Not really, or very little. Are we talking about a 3-D dataset, like a CT or MRI volumetric image? Or just simply a 1-D situation where we have some number of elements in Z and the value of each element of Z is the depth into or above some material?
Please attach your data.
So, does Z go from say 20 to 10000 in 951 elements, but without a constant delta between each pair of elements in Z. Like it might be 0.1 between one pair of elements but 1.4 between a different pair of elements? And you want to resample that range 20-10000 with uniform spacing of 0.25. So the number of elements would be (max(z) - min(z)) / 0.25? Then you can just use linspace():
minValue = min(Z(:));
maxValue = max(Z(:));
numElements = (maxValue - minValue) / 0.25;
zUniform = linspace(minValue, maxValue, numElements);
Brian Robinson
Brian Robinson 2020년 9월 20일
Not really, or very little. Are we talking about a 3-D dataset, like a CT or MRI volumetric image? Or just simply a 1-D situation where we have some number of elements in Z and the value of each element of Z is the depth into or above some material?
It is simply a 1-d dataset where z is the depth below ground surface.
Please attach your data.
Please see attached.
So, does Z go from say 20 to 10000 in 951 elements, but without a constant delta between each pair of elements in Z. Like it might be 0.1 between one pair of elements but 1.4 between a different pair of elements? And you want to resample that range 20-10000 with uniform spacing of 0.25. So the number of elements would be (max(z) - min(z)) / 0.25? Then you can just use linspace():
As you will see from the data, z is not in constant increments but varies widely. In some cases delta_Z is > 0.25 so in this case the row should be left. Using linspace command can create a uniformly spaced vector, but that won't help in this case as the function will not know which rows of the table to consolidate.

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 9월 19일
Instead of deleting the rows, I suggest using interp1() to get the required output
z = .. % 951x1 vector
x = .. % 951x1 vector of data points
z_new = 0:0.25:max(z); % new z vector have increments of 0.25
x_new = interp1(z, x, z_new); % x_new are data points corresponding to z_new.
  댓글 수: 6
Brian Robinson
Brian Robinson 2020년 9월 20일
I tried this code, but I don't think its suitable because data in the z column is changed and also the data in the other column of the table is changed during the interp1 operation. I need the original z values to be preserved (other than when the increment size is too small deleting the entire rows of the table) and all the data from the corresponding columns to be preserved.
I have made that delta_Z column for ease in cleaning the table. So for example, the 'cleaned' table would look the same for the first 9 rows until we get to a delta_Z of 0.0488. The entire rows where delta_Z = 0.0488, 0.0518, 0.0518, 0.0488 can be deleted as these increments total less than 0.25. So the 'cleaned' table would go from delta_Z = 0.2560 to delta_Z = 0.0518 in row 10. And the other columns such as stroke for row 10 (= 1.5506) are preserved.
I hope this clarifies.
Ameer Hamza
Ameer Hamza 2020년 9월 20일
I think you want something like this
load pile_data.mat
purdueUS52MODIFIEDS2(1,:) = []; % first row is NaN, removing it
data = table2array(purdueUS52MODIFIEDS2);
count = 1;
while size(data, 1) ~= count
if data(count+1, 20) < data(count, 20)+0.25
data(count+1, :) = [];
else
count = count + 1;
end
end
data(2:end, 21) = diff(data(:, 20));
table_new = array2table(data, 'VariableNames', purdueUS52MODIFIEDS2.Properties.VariableNames);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by