Writing a code to determine the gradient change in a profile
2 views (last 30 days)
Show older comments
Hi,
I'm trying to write a code which can determine the gradient change in a given profile. However the code is unable to determine the same correctly and giving incorrect results. For the pic1 below it should give me the width of the region where it is a steep gradient determined.
However for pic2 below it shouldn't as there is no steep gradient compared to pic1
The code is as below:
clear width;
global width;
global data;
for i=1:max(length(data.variable.t))
for j=1:max(length(data.variable.x))-1
change_p = (abs(data.variable.gradpressure(i,j+1))-abs(data.variable.gradpressure(i,j)))/abs(data.variable.gradpressure(i,j));
%disp(change_p)
if change_p > 0.1
disp("steep gradient found")
width(j)=1-data.variable.x(j);
disp(width)
else
disp("no steep gradient found")
end
end
end
the data.variable.gradpressure is a 1000x100 matrix with t along the vertical and x along the horizontal.
with regards,
rc
0 Comments
Accepted Answer
John D'Errico
on 28 Jun 2024
Edited: John D'Errico
on 28 Jun 2024
Your problem lies in this line:
change_p = (abs(data.variable.gradpressure(i,j+1))-abs(data.variable.gradpressure(i,j)))/abs(data.variable.gradpressure(i,j));
You divide by one of the elements, apparently hoping to scale things, so that you can compare then to a simple unit-less value 0.1. But what happens when the denominator is very near to zero? Look at the numbers at the beginning of the curve!
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!