cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

histogram

MortezaA
1-Visitor

histogram

I have these two sets of data one a vector being the length of particles(L),and the other a vector of the number of particles of a particular length(N). I can plot N versus L alright but the problem is the points in L are not equally spaced, therefore the N (Vs.)L plot is not exactly a histogram. My question is how to convert these two sets of data into a histogram?

making a single vector out of L and N ( a vector of length where each particular Li is repeated Ni times) is out of question since the elements in N are in the order of millions and the produced vector will be bigger than what mathcad can handle.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:MortezaA)

So here is a third version of mk_histo(). A very little bit slower (noticable only with big vector v and a high number of intervals). This time the third parameter can either be a positive integer or a vector with interval limits. Same meaning as the first parameter in the built in functions hist() and histogram().

View solution in original post

14 REPLIES 14
Werner_E
25-Diamond I
(To:MortezaA)

The Mathcad functions hist() and histogram() wont work for you unless you create the big combined vector you described. So I guess you will have to write a small program to do what you want.

Maybe you set up and post a demo wirksheet with dummy data (does not need to be the millions values you described) and state what kind of histogram you expect.

Werner Exinger wrote:

Maybe you set up and post a demo...

I can only this way to create a histogram in Prime

Do you know one better way?

(About this task - http://communities.ptc.com/videos/3543)

GL.png

I can only this way to create a histogram in Prime

Unfortunately MortezaA cannot use histogram(), like you suggested, because he is not able to create the necessary datavector, as he wrote. To explain it with your example (btw, your column headers are interchanged): you have one vector with all possible heights and a second one with the number of people being that tall. The values in the first vector are not equally spaced and so the two vectors do not apply for a true histogram.

In your example you have a dataset with only 48 samples and are creating a histogram with 1000 bins!?? Also I think that plot type "column trace" is more suitable for histogram plots that the "line trace" in your sheet.

I don't know what Mortezaa expects from the histogram and in which format he would need the histo-data as a result, but I guess he is in need for something like the following (I am assuming people are using real Mathcad unless otherwise stated):

09.01.png

I believe a histogram like what you made out of your L and N (where both L and N are not equally spaced) is what I'm looking for .

Just one question .what is that mk_histo(L,N,20) ?

it appears it is not a defined function in mathcad.( at least in mine!!)

Werner_E
25-Diamond I
(To:MortezaA)

Just one question .what is that mk_histo(L,N,20) ?

Just as I wrote before - I don't think that the built-in functions can do what you want. A small self written routine is necessary. Thats what mk_histo (aka make histogram) is - a routine I wrote to do what I thought you needed. Here is the file.

First parameter (v) of the routine ist a vector with the values you want to categorize your data for. Its the particle length in your problem (I had "values" in mind, so the v). The second parameter is a corresponding vector with the number of particles ("count" --> c). v and c must be vectors of same dimension - its a quick hack and so there is no error checking built in. The third parameter "n" is the number of intervals you want your data sorted in. The range [min(v); max(v)] is divided in n intervals of equal length. With exception of the first interval the lower end of each interval counts for the preceding interval, so it counts all occurencies of lower<value<=upper.

The output of the routine is a n x 2 matrix.The first column contains the midpoints of the intervals. The second column represents the frequencies with which values in data fall into the intervals.

In contrast to histogram() "n" must be an integer (in histogram() and hist() it could also be a vector with interval endpoints).

Werner_E
25-Diamond I
(To:MortezaA)

The first mk_hist() choked on same rare occasions because of round off errors, so I rewrote it - shorter, more to the point and more reliable (I hope).This time it was more convenient to chose lower<=value<upper (exception is the last interval, of course).

10.01.png

Werner Exinger wrote:

I can only this way to create a histogram in Prime

In your example you have a dataset with only 48 samples and are creating a histogram with 1000 bins!?? Also I think that plot type "column trace" is more suitable for histogram plots that the "line trace" in your sheet.

Thanks, but no other way to plot a histogram in Prime

Valery Ochkov wrote:

Thanks, but no other way to plot a histogram in Prime

"Column trace" IS available in Prime and I see no reason why my self written program should not work in Prime. Plotting a histogram never was something special in Mathcad as long as we could format a plot as bar plot (or "column trace" in Prime). Its the creation of the necessary vectors which was the problem in this thread as Mathcad does not offer something suitable on its own.

Werner Exinger wrote:

Valery Ochkov wrote:

Thanks, but no other way to plot a histogram in Prime

"Column trace" IS available in Prime

Thanks, now I see!

But I can not correct edit numbers on the X scale

Valery Ochkov wrote:

But I can not correct edit numbers on the X scale

You CAN apply a better and more appropriate scale (either have the ticks at the center of the intervals or at their ends), but its unnecessarily complicated to do so and has some quirks (See attached file).

Neither mathcad nor Prime can do that out of the box but IMHO they should.

Plots in Mathcad never were really top notch with a serious need for improvements, but Primes plots are incredibly worse in most respects und much more uncomfortable to handle!

10.01.png

LG-Prime.png

Sorry, I don't understand what you mean.

Are you after integer scale values? That shouldn't be that difficult but is IMO not appropriate for a histogram - at least nor for one with just a few bins..

10.01.png

Still not sure what you are looking for, Valery. Do you rather have in mind a histogram with intervals of different length? Are the values you marked in your plot the upper interval limits? Thats fairly easy to do, again using histogram(). But this time it seems impossible to get axis tick values at interval midpoints or interval endpoints, as Prime only allows for equidistant ticks.

10.01.png

We may indicate the interval length/limits by drawing boxes:

10.01.png

But I think its OK that Prime draws every bar of equal width. That way the area of the bars are comparable and its the area we perceive when we look at that kind of plot.

Werner_E
25-Diamond I
(To:MortezaA)

So here is a third version of mk_histo(). A very little bit slower (noticable only with big vector v and a high number of intervals). This time the third parameter can either be a positive integer or a vector with interval limits. Same meaning as the first parameter in the built in functions hist() and histogram().

Announcements

Top Tags