I'm relatively new to processing (and code in general) and trying to learn to use Java libraries. I found an example online but it gives an error, and I can't tell why.
The error is "unhandled exception type ParseException" Here's the code:
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
String dateInput = "10/31/1999";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy");
Date date = sdf.parse(dateInput);
cal.setTime(date);
System.out.println("Day Of Week: " + cal.get(Calendar.DAY_OF_WEEK));
(I'm still a beginner) I'm trying to think of an efficient way to calculate median values for a lot of data. I need to ignore zero values and only calculate the median of the non-zero values. I don't think I'm using sort correctly, nor does this seem like an efficient approach in general. I have 2 questions:
1. Why does this code return "[F@1fcabd4" in the print statement for each entry in median?
2. Is there a more efficient way to do this overall?
Thanks!
void meanMedian(boolean leftRight) {
if (!leftRight) {
median = new float[totalSeconds + 86400];
for (int i = 0; i < totalDays; i ++) {
int skipped = 0;
float [] edaToday = new float[86400];
for (int p = 0; p < 86400; p++) {
edaToday[p] = totalEda[i*86400 + p];
if (totalEda[i*86400 + p] == 0) {
skipped ++;
}
}
sort(edaToday);
reverse(edaToday);
sort(edaToday, 86400-skipped);
float [] medianArray = new float[86400 - skipped];
I'm having a pretty strange problem, hoping someone can see whatever it is I'm missing.
I created a new function, and I keep getting the "the function after() does not exist" I tried a lot of usual stuff like changing the name, return type, etc. None of that worked. Then I started messing with other functions and found that for some reason in this particular block, if I add a function it throws things off, even when I'm just copying and pasting an existing function. The issue is in the after() function in the dayOfData class. I've been focusing on that, and messing with date() which is right there, to try to debug. The strangest part is that if I copy date and make it date2() it works when I call it in setup but can't find it when I call it in this other spot. I'm beginning to think I'm going crazy, wonder if you can see something I'm missing?
(It's too long to include everything, so I included the parts that seem relevant, problem code is in red)
Slider dial;
CalendarButtons[] day;
CompareButtons[] compare;
ZoomButton[] zoomButton;
DayOfData[] dataDay;
SideButtons leftButton;
SideButtons rightButton;
//parse files for each day and assign date and day of the week
dataDay = new DayOfData[totalDays];
//sampleDay = new DayOfData("2011-07-09", "Saturday");
for (int i = 0; i < totalDays; i++) {
dataDay[i] = new DayOfData(day[i].date(), weekdayName[i]);
I'm new to using objects and classes, and having some kind of logic problem with sliders. I hav 2 sliders, A and B. B works perfectly, but A doesn't reset when I let go. Can anyone see why and help me, please? Thanks!
Slider sliderA;
Slider sliderB;
int topRowY = 4;
int topRowY2 = 306;
int midRowY = 348;
int midRowY2 = 568;
int bottomRowY = 610;
int bottomRowY2 = 674;
int bracketHeight = 10;
int sliderPositionA;
int sliderPositionB;
void setup(){
rectMode(CORNER);
smooth();
size(1408, bottomRowY2+4);
background(255);
sliderA = new Slider(topRowY2 +bracketHeight + 2, 5, 1);
sliderB = new Slider(midRowY2 +bracketHeight + 2, 64, 5);
I'm new to Processing and having an error which seems like a rookie grammar mistake, but I can't tell what the issue is. I am trying to check what the value of a string in an array is and print it if it is a certain value. It throws a null pointer exception. The code is below, with the trouble spot in red. I tried with a few other of the arrays and it didn't work for any, but I know the problem isn't that the valu is incorrect. Would appreciate any suggestions. Thanks!
int annoTotalPoints;
//these are variables for the time to x function
int xValue;
String timeClock;
float average;
int annoLineCount= 1967;
//creating arrays for each column
String [] participant = new String[annoLineCount];
String[] annotationsDates = new String[annoLineCount];
String[] annoType = new String[annoLineCount];
String[] mastered = new String[annoLineCount];
String[] preferred = new String[annoLineCount];
String[] description = new String[annoLineCount];
String[] comments = new String[annoLineCount];
String[] onsetTime = new String[annoLineCount];
String[] offsetTime = new String[annoLineCount];
int[] onsetX = new int[annoLineCount];
int[] offsetX = new int[annoLineCount];
void setup() {
size(1440, 300);
background(200);
stroke(255);
smooth();
//read the annotations file and find out how many lines it has
I'm new to Processing and trying to work on a program to view some data. There are 2 separate data sources (.txt files), one is a series of data points taken every 8th second, with a start time. The other is a series of events marked separately at certain times. I have the data at 8th seconds working fine, but want either to make each data point know what time it is or make each of the data points with time codes know which 8th second they belong to. Can anyone suggest a smart way to merge the data so it can be aligned on the same x axis?
Thanks!
Here's my code with the first set of data.
float[] t,e;
float average;
int total_points;
float total;
PFont font;
void setup(){
String[] lines;
int index = 0;
size(1200, 300);
background(200);
stroke(255);
smooth();
font= loadFont("Gotham-Light-12.vlw");
textFont(font);
//reads the data from the file
lines = loadStrings("q2.txt");
//println(lines.length);
println(lines[5]);
int total_points=lines.length-8;
println(total_points);
//total_points=1000; //allows me to use fewer points to troubleshoot
//moves (0,0) to (0, 300)
t= new float[total_points];
e= new float[total_points];
for (int i=0;i<(total_points);i++){
String[] firstline=lines[8+i].split(",");
float edaRaw = float(firstline[5]);
//print there to see what values are in array
//print(((i+1.0)/8.0));print(',');
//println(edaRaw);
//figure out how many entries in a day, alway use same #, this is 6 hours