NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
June 02, 2020, 10:34:57 pm

Acting locally and thinking globally. ...Wisdom

 Pages: [1]   Go Down
 Author Topic: histogram how can i dont count values =0 ?  (Read 9563 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member

Offline

Posts: 1796

http://weelookang.blogspot.com

 « Embed this message on: March 22, 2010, 03:37:19 pm »

Hi prof,
histogram how can i dont count values =0 ?

http://www.um.es/fem/EjsWiki/Main/ElementsHistogram

 *** There are 1 more attached files. You need to login to acces it! Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3085

 « Embed this message Reply #1 on: March 22, 2010, 04:34:50 pm » posted from:Taipei,T'ai-pei,Taiwan

Have you tried to assign a variable to "Enabled", then set it to false if you want to disable adding data to histogram.
Set it to true when you want to add values to histogram.
 Logged
lookang
Hero Member

Offline

Posts: 1796

http://weelookang.blogspot.com

 « Embed this message Reply #2 on: March 22, 2010, 06:26:16 pm »

sori was in a hurry to post the laptop battery dying so i didn't explain clearly my problem.

Have you tried to assign a variable to "Enabled", then set it to false if you want to disable adding data to histogram.
Set it to true when you want to add values to histogram.
i did but it didn't work the way i wanted.

the problem i am trying to solve is this.

i have n = 20
i have speed[j] = 20 numbers correct and required but i also have 180 zero values because i declared n = nmax and nmax = 200
so the speed[j] actually has 20 numbers spread around 500 but 180 values =0
thus the histogram is displaying a very high probability about 0.8 for the bin = 0 to 50

i want to count only the n = 20, speed[0] , speed[1], speed[2],......speed[19] values in the histogram.

i been thinking and thinking but i can't formulate the codes. and was hoping for an easy selectable option in the Ejs histogram list of field.

chance for tips or example codes for me to do some trial and error?

i tried to do but it makes the applet cannot display the particles.

sometime like

Code:
for (int i=0; iif (speed[i] > 0.1) {
histogramspeed[i]= speed[i];
histogramn = histogramn+1;
}

 Screen shot 2010-03-22 at PM 07.18.59.png (106.13 KB, 1890x756 - viewed 726 times.) « Last Edit: March 22, 2010, 06:34:45 pm by lookang » Logged
lookang
Hero Member

Offline

Posts: 1796

http://weelookang.blogspot.com

 « Embed this message Reply #3 on: March 22, 2010, 08:33:09 pm »

i think i got it!!
histogram

if (speed[j]==1) {
histogram=false;
}
else {
histogram = true;
}
no worries!
 Logged
lookang
Hero Member

Offline

Posts: 1796

http://weelookang.blogspot.com

 « Embed this message Reply #4 on: March 22, 2010, 09:10:50 pm »

i am not sure that the code work but i change the initial value of the number of particles n = 200 and the problem seems to disappear.

 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3085

 « Embed this message Reply #5 on: March 22, 2010, 09:18:15 pm » posted from:Taipei,T\'ai-pei,Taiwan

I am sorry that I did not really fully understood what was your problem.
But I am glad to hear that the problem seems to be solved!
 Logged
lookang
Hero Member

Offline

Posts: 1796

http://weelookang.blogspot.com

 « Embed this message Reply #6 on: March 22, 2010, 09:33:56 pm »

when i use n=200, beautiful see picture
.

the problem appears when i use n any number less than 200 because i think the array is [n]
so speed[j] has 200 values which is pipe into the histogram despite the slider value at n = 21 for example.

see the picture

haiz
i think i didn't solve it

any tips!
i attached the source in case u need to understand the problem.
 noproblemhistogram.png (45.01 KB, 1233x527 - viewed 499 times.)  histogramproblembecausenis200forthearraY.png (41.85 KB, 1225x529 - viewed 727 times.) *** There are 1 more attached files. You need to login to acces it! « Last Edit: March 22, 2010, 09:38:16 pm by lookang » Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3085

 « Embed this message Reply #7 on: March 22, 2010, 10:40:46 pm » posted from:Taipei,T\'ai-pei,Taiwan

The histogram find it's number of element from it's own definition.
It was define as speed[nmax] , so the element always use nmax as the number of element for speed.
When you drag slider to change value of n, it does not change the size of the speed array.

Code:
if(n at the last line in initlalize page to fix it.

I also un-comment the following at "Brownian" page under "Fixed relations".
Code:
//if(!accumulateData) _view.speedHistogram.clear();
The above code will cause error , when there is no data in the histogram (nothing to be clear).

Please check out the attached xml file.
 *** There are 1 more attached files. You need to login to acces it! Logged
lookang
Hero Member

Offline

Posts: 1796

http://weelookang.blogspot.com

 « Embed this message Reply #8 on: March 22, 2010, 10:59:31 pm »

Code:
if(n < nmax)speed=new double[n];

clever! thx! i would have never been able to dream up this code, i learn something new again!

The histogram find it's number of element from it's own definition.
It was define as speed[nmax] , so the element always use nmax as the number of element for speed.
When you drag slider to change value of n, it does not change the size of the speed array.

Code:
if(n < nmax)speed=new double[n];
at the last line in initlalize page to fix it.

I also un-comment the following at "Brownian" page under "Fixed relations".
Code:
//if(!accumulateData) _view.speedHistogram.clear();
The above code will cause error , when there is no data in the histogram (nothing to be clear).

Please check out the attached xml file.

i also added the tip on http://www.um.es/fem/EjsWiki/Main/ElementsHistogram

If the simulation uses [n] array together with a slider for [n], initialize page may need to add code” if(n < nmax)speedarray=new double[n]; “ for histogram to display array correctly as [n]. Check out http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1487.msg5607#msg5607  for in-depth discussion.
 « Last Edit: March 22, 2010, 11:21:42 pm by lookang » Logged
 Pages: [1]   Go Up
Acting locally and thinking globally. ...Wisdom