Error: "Dimension argument must be a positive integer scalar within indexing range" using trapz
Show older comments
x_24= [0; 4.6958; 5.6732; 14.2002; 15.4490; 16.0151; 17.9994; 21.7987; 24.1082; 29.8818; 37.4162; 41.1113; 55.6853; 59.9431]
z_24=[ 6.1876; 7.1381; 7.2346; 4.4075; 4.4321; 4.2854; 3.9659; 3.4729; 3.1695; 2.2887; 1.2414; 0.8183; -0.0147; -0.2389]
NM_18=0.82;
MHWS_18=1.5-NM_18;
z_MHWS_24=z_24-MHWS_18;
MHWS_vector_18=repmat(MHWS_18,79,1);
figure(1)
plot (x_24,z_MHWS_24,'Yellow')
hold on
plot(MHWS_vector_18,'Blue')
hold off
x=x_24;
z=z_MHWS_24;
xi=5.67;
xf=14.20;
xRange = [xi,xf];
% find logical indices for range of interest
idl = x >= xRange(1) & x <= xRange(2);
% provide just values of interest to trapz
area_selected=trapz(x(idl),z(idl))
area_total=trapz(x,z)
The error that is happening is in the last two lines of the code above (from bottom to top).
Accepted Answer
More Answers (0)
Categories
Find more on Numerical Integration and Differentiation 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!