MATLAB help: determining the area under a plot (not a curve whose form is known)

In summary, the conversation involves a project that requires plotting histograms of N images and using a curvilinear approximation. The next steps involve determining the area under the curve and finding the minimum area value for a specific image number. The use of the MATLAB command 'trapz' is suggested for step 3, but there is uncertainty about its application. The conversation ends with a clarification on the use of trapz and plotting the peaks of the histogram.
  • #1
maverick280857
1,789
4
Hi

For a project (described https://www.physicsforums.com/showthread.php?t=227684"), I have to do the following for N images:

1. plot the histogram of each image, using

imhist(x)

2. plot a curvilinear approximation to the histogram, using

plot(imhist(x))

3. determine the area under the plot generated in step 2

4. Plot a curve of area value versus image number (index) and determine the image number for which the area value is a minimum.

I am not sure how to do step 3 and also whether steps 1 and 2 are correct.

Can someone please help?

Thanks and cheers
vivek
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
If step 2 is continuous then try the MATLAB command 'trapz'.
Go:
help trapz
in the MATLAB command window. Hopefully you can do:
trapz(imhist(x))
 
  • #3
Should I do

trapz(imhist(x))

or

trapz(plot(imhist(x))

?

plot(imhist(x)) plots the histogram with the peaks joined by a not-so-smooth curve...
 
  • #4
You should do:
trapz(imhist(x))

Now you say that plot(imhist(x)) plots a histogram with peaks joined by a curve? I assume you want the area under that curve? If that's the case I don't think trapz will help - you need to JUST plot the peaks and trapz will give the area under that curve.
 
  • #5
Thanks
 

1. What is the purpose of determining the area under a plot in MATLAB?

The area under a plot in MATLAB is often used to calculate the integral of a function, which can provide useful insights into the behavior and properties of the function. It can also be used to approximate the area between the plot and the x-axis, which can be useful in applications such as data analysis and visualization.

2. How do I determine the area under a plot in MATLAB?

To determine the area under a plot in MATLAB, you can use the trapz function, which calculates the integral using the trapezoidal rule. This function takes in the x-values and y-values of the plot as input and returns the estimated area. Alternatively, you can also use the integral function, which allows for more flexibility and accuracy in the calculation.

3. Can I determine the area under a plot if the curve's form is not known?

Yes, you can still determine the area under a plot even if the curve's form is not known. This is because the trapezoidal rule and the integral function do not require knowledge of the exact function, but rather just the values of the plot at different points. However, the accuracy of the calculation may be affected if the curve's form is not known.

4. How can I plot the area under a plot in MATLAB?

To plot the area under a plot in MATLAB, you can use the fill function, which fills the area between a curve and the x-axis. You will need to specify the x-values, y-values, and the color or pattern to fill the area with. This can be useful for visualizing the calculated area and comparing it to the actual plot.

5. Are there any other methods for determining the area under a plot in MATLAB?

Yes, there are other methods for determining the area under a plot in MATLAB, such as the Simpson's rule and the cumtrapz function. These methods may provide more accurate results for certain types of functions, but they also require more computational resources. It is recommended to use the trapz or integral functions for general use.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
983
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Replies
1
Views
765
Replies
2
Views
238
Back
Top