bool array and for loop in Arduino - arduino

I have an array
int lc[2][2]=
{
{HIGH,LOW},
{LOW,HIGH}
};
and I want to create a for loop with
for(lc[2][2]==HIGH){...}
but it only works for
for(lc[1][1]==HIGH){...}
I don't understand what I'm doing wrong. Thank you!

Your two-dimensional array consist of two rows and two columns.
You can access the values with lc[0][0] and lc[1][1].
You have not assigned the index 2 a value, so you would not get into the loop.

Related

Different array types, for comparison in the set_difference() function

I'm having some issues getting expected results from set_difference(). I assumed I was comparing two dynamic arrays, but I'm not sure where the gap is. The only additional insight I have is that when I compare the two arrays using the gettype() function, I get the following:
First array
Created using a make_list aggregation, e.g.
| summarize inv_list = make_list(Date)
When I run gettype() on the array:
"type_inv_list": array
Second array
Created through a scalar function
let period_check_range = todynamic(range(make_datetime(start_date), datetime_add('day',8,make_datetime(start_date)),1d));
When I run gettype() on the array:
"type_range___scalar_90e56a216d8942f28e6797e5abc35dd9": array
Any guidance on how to make these arrays work so I can use the set_difference() function?
You're missing toscalar() (see doc) in the first array. When you run | summarize ... you get a table as a result, but what you actually want is a single scalar, what's why toscalar() is needed.
Here's how to achieve what you want:
let StartDate = ago(10d);
let Array1 = toscalar(MyTable | summarize make_set(Timestamp));
let Array2 = todynamic(range(make_datetime(StartDate), datetime_add('day',8,make_datetime(StartDate)),1d));
print set_difference(Array2, Array1)
By the way, you probably want to use make_set and not make_list as you're not interested in duplicate values.

Counting the number of elements of an array but with a condition

I have an array with real numbers, say A. I have calculated the mean as np.mean(A)
Now I want to check how many elements fell below the mean and how many above.
for example
A = [ 1 2 3 5] so the average is 2.75. So, i have two elements below the average and two elements above.
Any help will be appreciated
Not sure if this is what you are looking for, but you could do:
function mean(array){
var sum=0;
for (item in array){
sum = sum + array[item];
}
return sum/(array.length)
}
function belowMean(array) {
return array.filter(function(item){
return item < mean(array);
});
}
var a=[1,2,3,4];
alert(mean(a));
alert(belowMean(a)); //you'll get an array with those elements below the mean.
alert(belowMean(a).length); //you'll get how many elements are below the mean.
It's ugly though, I'd rather modified the array prototype to tho so.
How about loop it twice? First time for average value and second time for your count?

how to store contetnts of a several array in a matrix in C

I am trying to store contents of different vectors in a matrix.
length of vectors are different and they are all strings. lets say:
A=["MXAA', "MXBB", "MXCC"]
B=["JJJ", "LKLKLKL"]
so the new matrix should look like the following:
C= [MXAA, MXBB, MXCC;JJJ, LKLKLKL, 0]
is the a way to do that in C?
thanks
You would need to create an array of pointers to pointer to the element type (which in your case is a pointer to char).
The problem you need to consider is that every array is different size; so I suggest you store the size of the arrays, or you will quickly end up running over the bounds of an array. This sounds a bit like a custom type.
typedef {
int n;
char **strArr;
} stringArray;
stringArray *str2d;
str2d = (stringArray*) malloc(2*sizeof(stringArray));
str2d[0].n=3;
str2d[0].strArr = (char**)malloc(3*sizeof(char*));
str2d[0].strArr[0] = "MXAA";
str2d[0].strArr[1] = "MXBB";
str2d[0].strArr[2] = "MXCC";
str2d[1].n = 2;
str2d[1].strArr = (char**)malloc(2*sizeof(char*));
str2d[1].strArr[0] = "JJJ";
str2d[1].strArr[1] = "LKLKLKL";
If you want to access an element you use similar addressing - but check that you stay within bounds!
I deliberately did this in very explicit steps, hoping this makes the principle clear. There are better ways to do this but they are more obscure (or not "standard C")

Type mismatch, cannot assign System.Data.DataRowCollection to array of System.Data.DataRow

I want to be able to traverse through a list of DataRow using For each loop as follows.
ArrayOfRows: Array of DataRow;
ArrayOfRows := dbtable.Rows;
for each therow in ArrayofRows do
begin
ITagList.Add(therow['TAGNAME'].ToString);
end;
But I keep running to the error,
"Type mismatch, cannot assign System.Data.DataRowCollection to array
of System.Data.DataRow."
How do you traverse through a list of rows in a datatable?
Thanks in advance,
Use System.Data.DataRowCollection.CopyTo(), which is designed to do exactly this.
public override void CopyTo(
Array ar,
int index
)
The parameters are the array you want to copy into, and the zero-based index where the copy should start.

LINQ to create int array of sequential numbers

So instead of writing a looping function where you instantiate an array and then set each index value as the index, is there a way to do this in LINQ?
Enumerable.Range(0, 10) will give you an IEnumerable<int> containing zero to 9.
You can use the System.Linq.Enumerable.Range method for this purpose.
Generates a sequence of integral numbers within a specified range.
For example:
var zeroToNineArray = Enumerable.Range(0, 10).ToArray();
will create an array of sequential integers with values in the inclusive range [0, 9].
You might want to look at Enumberable.Range
For Each( var i in Enumberable.Range(1,5).ToArray()){
Console.WriteLine(i)
}
would print out 1,2,3,4,5

Resources