Subscribe Bookmark RSS Feed

Setting values to a cell

miguello

Community Trekker

Joined:

Jan 27, 2016

Hello all,

It's been some time since I did any programming in JSL, so I'll be asking some basics questions which I did not find in the manuals.

1. How, using a JSL, I can set a specific value to a specific Col/Row?

2. I need to do that in a For loop. Let's say I need to run a loop from 1 to number of rows, and assign (for now) the same number to each Row of a Specific column. How do I do that this way?

3. Specific example. I have M sets of N measurements. I have datetime for each measurement. I know that each mth measurement was done in order. But do not have column that says what set it is, I only have column that has the measurement.

In other words I have only first column, and I need to make the second.

I know how to do the logic - See the difference between current row and the previous one, and as soon as it's not 1, iterate the MeasSet counter.

But how do I iterate and how do I write this FOR loop?

I wrote it once, but lost the code and starting from the beginning here.

Counter1MeasSet

1

1
21
31
41
51
12
22
32
42
52
1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Here are some examples that may give you an idea:

dt = Current Data Table();

// 1. With a column variable

col = Column(dt, "MeasSet");

col[6] = 2;

// or directly

// "dt" in Column() is optional but good if same column name occurs in other open tables

Column(dt, "MeasSet")[1] = 1;

// 2.

For Each Row(col[] = 1);

// 3.

For(i = 1, i <= N Rows(dt), i++,

    If(:Counter1[i] == 1,

        col[i] = set = 1,

        col[i] = set

    );

    set++;

);

2 REPLIES
Solution

Here are some examples that may give you an idea:

dt = Current Data Table();

// 1. With a column variable

col = Column(dt, "MeasSet");

col[6] = 2;

// or directly

// "dt" in Column() is optional but good if same column name occurs in other open tables

Column(dt, "MeasSet")[1] = 1;

// 2.

For Each Row(col[] = 1);

// 3.

For(i = 1, i <= N Rows(dt), i++,

    If(:Counter1[i] == 1,

        col[i] = set = 1,

        col[i] = set

    );

    set++;

);

miguello

Community Trekker

Joined:

Jan 27, 2016

Thanks,

I came up with this solution:

 

i=1;

For Each Row(

If ((:Counter1 - lag(:Counter1))!=1, (i++; :MeasSet=i) , (i=i; :MeasSet=i), (:MeasSet=i) );

);

I need to stress two things:

1. Needs to be !=, not ==

2. Had to put i=i, otherwise script asks if I want to use comparison "==" or assign value "=" for next MeasSet.