Apologies if this has already been answered in another form elsewhere on the forums, however I couldn't find any answers that helped me directly with my code. I currently have code that maps the profile and area of a channel. I wish to have a horizontal y value across my channel width to simulate the fluctuating water level, the example line is shown in the image as the green line. So for example I would want to calculate and shade the area underneath the greenline only.
With the function would I be able to loop the same function for a range of values for the horizontal values, to provide an output I could then plot? A vector form would be ideal if possible.
I've already tried to use the area and fill commands unsuccesfully, or maybe I was not using the correct format for them.
I've also attached the relevant code below, any help would be much appreciated.
x = [ 0 1 2 3 4 5 6 7 8 9 10 11 12];y = -[0 -0.5 -0.8 -0.8 -1 -1.1 -1.2 -1.2 -1.4 -1.2 -1.1 -1 0]; % y values in image were produced by rand function
subplot(2, 1, 1);area(x,-y)grid on;hold on;for k = 1 : length(x) xline(x(k), 'Color', 'k');endyt = yticks;for k = 1 : length(yt) yline(yt(k), 'Color', 'k');endplot (x, -y, 'r.-', 'LineWidth', 3, 'MarkerSize', 30)hold onyline(-0.5,'g',11);xlabel('Chainage (m)', 'FontSize', 11);ylabel('Depth (m)', 'FontSize', 11);An = (trapz(x,y)); % Overall area.
% Compute areas within each pair of x locations.
midpoints = (y(1:end-1) + y(2:end))/2;deltax = diff(x);Ani = deltax .* midpoints;subplot(2, 1, 2);bar(x(1:end-1)-x(1)+ 0.5, Ani);title('Areas of Slices', 'FontSize', 14);xlabel('x', 'FontSize', 11);ylabel('Area (m^2)', 'FontSize', 11);grid on;
Best Answer