Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
7 posts
|
Hi all,
I have a matrix of data points with x,y coordinates in two arrays (x_h_row and y_h_row). I want to do straight line (y = ax + b) curve fitting with each row, find out about parameter "a" for each row, then put all the "a" values in an array or result table, so that I can get the average of a. Since x_h is increasing from left to right along each row of data points, my method is to use Fit.doFit every time when x_h[k] < x_h[k-1], i.e. it has come to the right end of each row. And then hopefully, by have the following in the beginning of each for loop: x_h_row = newArray(x_h.length); y_h_row = newArray(y_h.length); I can reset the two arrays and put new x_h, y_h values in, so that the next Fit.doFit will be done on next row with new data points. However, currently it seems the two arrays didn't get rebuilt within the for loop, and I'm getting "a" values based on a curving fitting on all the data points previously processed. Could anyone please help? for (k=1; k<x_h.length; ){ stop = 0; x_h_row = newArray(x_h.length); y_h_row = newArray(y_h.length); m = 0; n = 0; while (k < x_h.length && stop == 0) { if (x_h[k] > x_h[k-1]){ l = k; x_h_row[m] = x_h[k]; y_h_row[n] = y_h[l]; k = k + 1; m = m + 1; n = n + 1; } else stop = 1; } Fit.doFit("y = a*x + b", x_h_row, y_h_row); a = Fit.p(0); p = nResults; // variable for counting, initialising with 0 setResult("a", p, a); updateResults(); k = k + 1; } Or alternatively, if I can put the "a" I got from all the Fit.doFit on each row in an array, it would do too. But how can you put variables into an array? I tried the following but it didn't work. a_h_row = newArray(); p = 1; for (k=1; k<x_h.length; ){ stop = 0; x_h_row = newArray(x_h.length); y_h_row = newArray(y_h.length); m = 0; n = 0; while (k < x_h.length && stop == 0) { if (x_h[k] > x_h[k-1]){ l = k; x_h_row[m] = x_h[k]; y_h_row[n] = y_h[l]; k = k + 1; m = m + 1; n = n + 1; } else stop = 1; } Fit.doFit("y = a*x + b", x_h_row, y_h_row); a_h = Fit.p(0); a_h_row[p] = a_h; k = k + 1; p = p + 1; } Thanks, Danju -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Disable Popup Ads | Edit this page |