NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
October 21, 2017, 10:23:58 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
"Choose a job you love, and you will not have to work for a day in your life." ...Confucius (551-479 BC)
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

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

Posts: 1784


http://weelookang.blogspot.com


WWW
«
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
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
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 Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
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
use j instead of i
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;
}

Thanks for your help! Grin


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

Posts: 1784


http://weelookang.blogspot.com


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

i think i got it!!
histogram

use j instead of i
if (speed[j]==1) {
  histogram=false;
}
else {
  histogram = true;
}
no worries!
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
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.

will ask when need again Smiley
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
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 Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
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 Smiley

any tips!
i attached the source in case u need to understand the problem. Grin


* noproblemhistogram.png (45.01 KB, 1233x527 - viewed 335 times.)

* histogramproblembecausenis200forthearraY.png (41.85 KB, 1225x529 - viewed 552 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
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
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.

So I add
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 Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
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.

So I add
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
  Print  
"Choose a job you love, and you will not have to work for a day in your life." ...Confucius (551-479 BC)
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
how to make slider with fixed values for instance 1,2,5,10 50
Questions related to EJS
Fred Chuit 2 7140 Last post January 20, 2009, 09:23:48 am
by lookang
how to view the data values assigned into a array that is [5]*[5] for example.
Questions related to EJS
lookang 1 5592 Last post March 30, 2009, 05:54:58 pm
by Fu-Kwun Hwang
is there a quick way to count the number of Ejs simulations on NTNU Java Virtual
Questions related to EJS
lookang 0 2988 Last post December 19, 2011, 01:38:27 pm
by lookang
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.064 seconds with 23 queries.since 2011/06/15