text:
Embedded Stuff
on

## Android & Bluetooth & Arduino

I am trying to display sensor data on my Android phone (target 4.3) received from a transmitting arduino type device. The transmission takes place via Bluetooth. I am able to connect to the arduino …

## BLE Mini iBeacon (redbearlab)

I'm want to make a simple iBeacon test where an Arduino LED lights up when an iPhone with the proper application installed is nearby. Quick question: Is this possible with the BLE Mini from ...

## Control Arduino firmata with HC-05

I'm using the johnny-five library to control an Arduino Uno running StandardFirmata. I have a HC-05 bluetooth module that I want to use to wirelessly control firmata, but have yet to get it working. …

## Send More command (Val) to Arduino?

My project is controlling LED light by using Visual basic Program made by me. I have a little problem in my project, how can I send more command to the arduino from my PC? For example, This is the …

## arduino assign values to multidimensional array

I have an arduino project which uses a 2 dimensional array to track row/column info. If I try to assign a row,column pair to a particular element I get an error: expected primary-expression before …

3 hours ago

## Arduino Uno SoftwareSerial and Serial conflict

I have a very simple setup with an Arduino Uno R3 connected to my Windows 7 x64 with Arduino 1.0.1. I have a RF receiver connected to the Arduino on the DI10 port using the SoftwareSerial library. I …

3 hours ago

## Should I be doing any casting while sending data from C to arduino over serial?

My setup: Android device =(WiFi)=> Linksys router (WRT54G) =(serial)=> Arduino Android device : using sockets IO - connects to router Linksys router : Linux sockets IO - accepts a client Arduino : …

3 hours ago

## Send long array to arduino over serial from processing

So i build an 24x16 (hight of 16, length of 24) LED matrix and am using an Arduino Uno to control it. It is only a one color matrix and i am using an array to store all of the bits of data. This is …

## Transformer: primary side & secondary side current 180 degree out of phase

I am a novice in electrical engineering. I notice that in transformer the secondary side current & current referred to as primary are 180 degree out of phase from each other. But why it is so, I …

## How can KVL & KCL be derived from Maxwell equations?

How can KVL (Kirchhoff's Voltage Law) & KCL (Kirchhoff's Current law) be derived from Maxwell equations in lumped circuits?(Lumped network : if $d$is the largest dimension of the network and ...

## How can add a resistance to elecrtical madar without reduce voltage?

How can add a resistance to electrical network without reduce voltage?

## How to choose WiFi signal strength detecting sensors

We want to create robot that will localize itself by the signals of wifi routers. Which sensors should we buy to detect strength of 3 WiFi signal? Which of following is necessary for us? ...

## Issue communicating over serial to Arduino from Matlab

Update 2: Turns out adding a pause(2) after opening the serial port was all it needed. Update: I am able to manually enter the Matlab code into the Matlab command window and it will update the LEDs …

## How to reliably send large strings via serial port to arduino

I'm trying to send a large string to Arduino as constant as possible, But whatever i try it is never reliable, On c# I have: private void OnTimedEvent(Object myObject, EventArgs myEventArgs) { …

10 hours ago

## How to have wifi connected raspberry pi control an arduino?

I have an arduino uno that needs to respond to an iOS application with the internet being the medium. My initial plan was to use a wifi shield for the arduino, but since I can't get one at this time, …

10 hours ago

## Cannot send RGB color to arduino with as3

I'm in a project using arduino uno + led RGB + flash as3 but I've a little problem to send the information in order to be processed by arduino and show the color in the led RGB, I have an example of …

11 hours ago

## Arduino does not return from serial interrupt routine correctly

My program simply does nothing in loop. I set an interrupt for serial port (USART). When data comes, yes, it works and toggles the LED. But it just does it once. Once it got into the interrupt it ...

11 hours ago

## Combination of two signals to determine the end signal sent through Simulink code

Goal I'm trying to have a second signal (caused by force applied to a sensor's surface area), once it reaches a set minimum, to determine a servo motor's position. The motor's position is otherwise …

I know it's possible to change the clock prescaler at runtime. But is there a way to set the prescaler that is used at boot on an ATMega328? I'm aware of the fuses, but those are pretty permanent. I …

14 hours ago

## Transfer data to arduino via bluetooth

I am planning to transfer data between arduino and a mobile device. Right now, I can read data from arduino in mobile device, but can't send data to the arduino board. here is the code I am using for …

20 hours ago

## Feedback on Arduino class for LED circle animations

I'm fairly new to Arduino and C++ in general, coming from a heavy Python background. The code below is functional, but my lack of C++ knowledge is keeping me from spotting any errors in style, idioms …

21 hours ago

## How can electrons move along the conductive wire? ( seems to be a paradox )

Tangential components of the electric field across an interface between two media, with no impressed magnetic current densities along the boundary of the interface, are continuous. So: \$ n \times (E_2 …

## What does the electric field caused by a charged cylinder look like?

I am talking about a cylinder with a large enough radius:length ration that it cannot just be treated as a line. I would think that the electric field lines come out the curved and flat surfaces ...

## Charge of an electric wire

If an electric current is flowing through an electric wire, can we consider that wire charged? The answer is required with a proof. Can we consider the wire to be charged positively or negatively?

21 hours ago

## Regular ADK board vs Uno+USB Host Shield

Can anyone explain what advantages if any, there is in using a regular ADK board (Mega ADK or similar) vs using say, a Uno+ a USB host hsield? I'm concerned about the form factor of the former.

22 hours ago

## Why do power lines buzz more when it is low-humidity outside?

I have observed that the power lines buzz louder when there is less moisture in the air. Why is this? If it will help the lines are located on the foot hills of a nearby mountain.

23 hours ago

## How to use a low level language with Arduino

My problem is that Arduino's IDE is not enough for me lately. To briefly explain; I need to use interrupt when a data is available on serial port. But arduino IDE does not have that ability. It just …

yesterday

## Arduino at 5V but 8MHz

Is there any reason not to load the Arduino Pro 8Mhz bootloader onto a 5V arduino (custom design, just a standard ATMega328p)? I'm doing some battery backup stuff with it that doesn't play nice with …

yesterday


text:
# Frobenius, Ferdinand G.

## Subgroup formed by elements of order dividing n ★★

Author(s): Frobenius

\begin{conjecture}

Suppose $G$ is a finite group, and $n$ is a positive integer dividing $|G|$. Suppose that $G$ has exactly $n$ solutions to $x^{n} = 1$. Does it follow that these solutions form a subgroup of $G$?

\end{conjecture}

Keywords: order, dividing

format: plain


text:
# excel-vba function to filter an array and return an array

I have a function to filter a 2-d array.

It works. But I am not sure if the following mechanism is a sensible concept.

The idea is:

1. loop over the input array which is received as input_arr(y,x)

2. store the values in temp_arr(x,y), since in order to resize the y-dimension it needs to be last dimension, so I have to transpose the values as I store them

3. once the loop is done, transpose temp_arr(x,y) which becomes the return value

Public Function filter_arr(input_arr As Variant, col_index As Long, filter_value As Variant) As Variant

'the input_arr might be indexed starting from 0 or 1
Dim n1 As Long, n2 As Long
n1 = LBound(input_arr, 2)
n2 = UBound(input_arr, 2)

Dim temp_arr() As Variant
Dim y As Long, x As Long, count As Long
count = 0

If (LBound(input_arr, 1) = 0) Then
For y = LBound(input_arr, 1) To UBound(input_arr, 1)
If (input_arr(y, col_index) = filter_value) Then

ReDim Preserve temp_arr(n1 To n2, 0 To count)
For x = n1 To n2
temp_arr(x, count) = input_arr(y, x)
Next x
count = count + 1

End If
Next y

Else

'if LBound(input_arr, 1) = 1
For y = LBound(input_arr, 1) To UBound(input_arr, 1)

If (input_arr(y, col_index) = filter_value) Then

count = count + 1
ReDim Preserve temp_arr(n1 To n2, 1 To count)
For x = n1 To n2
temp_arr(x, count) = input_arr(y, x)
Next x

End If
Next y

End If

filter_arr = Application.Transpose(temp_arr)

End Function

Imagine that I have a ws in an .xlam file that contains product information which I've added as an add-in.

I have a function like =getProductData() which returns an array containing that data

So excel has a SORT function which works great with this kind of thing. I can do =SORT(getProductData(), 2, 1) to return my product data sorted by the 2nd column

But excel's FILTER function needs me to specify the data itself as its second parameter, not just its index, like in SORT

I can use INDEX to do something like =SORT(FILTER(getProductData(),INDEX(getProductData(),,3)="red",""),2,1) to filter my product data by the 3rd column if the value = red, then sort by the 2nd column of the resulting array

But I was hoping to do something like =SORT(filter_arr(getProductData(),3,"red"),2,1) to do the same

Naturally I'm still just playing around to determine what I can pull off - maybe using INDEX is the way to go and I'm trying to reinvent the wheel

• I would think about creating a class which provides the flexibility you want . I would suggest that internal to the class you convert the array to a collection of collections using either Collection, ArrayList or Scripting.Dictionary as your collection object (whichever is the best fit). Write methods or properties to expand/contract access individual items as required. Jan 12, 2021 at 11:25
• Just for some context, what is the purpose of this code; is it called from the worksheet as a UDF or from other vba code? What sort of data are you passing in, and is this just 1 step of a bigger process? Are you having performance issues? Update your question to include any of that sort of stuff if you can:) Jan 12, 2021 at 11:28
• I added some details of what my plans were for this function Jan 12, 2021 at 16:00
• Too short for a review, but VBA is slow and it's not too hard to make this work with spreadsheet formulae, but use LET or LAMBDA to avoid repeating the calculation: =LET(array,getProductData(),FILTER(array,INDEX(array,,3)="red")). Or better (but requires beta channel): FILTERIF = LAMBDA(array,filter_index,include_if,FILTER(array,INDEX(array,,filter_index) = include_if)) called like =FILTERIF(getProductData(),3,"red") Jan 13, 2021 at 16:33
• @Greedo Although I haven't used them, I believe that my answer would outperform Let and Lambda. In any case, not every version of Excel supports them. Jan 14, 2021 at 1:14

ReDim Preserve and Transpose are not free. I use this pattern when I need to filter an array:

1. Declare a 1-D array (Indices) with the same number of rows as the 2D array
2. When a match is found add the matches index to the Indices array and increment the counter
3. If there is matching data, declare a 2-D array (Results) with the same dimensions of the Input array but a row count equal to the counter
4. Iterate over the indices in the Indices array and add the matching values to the Results
5. Return the Results
6. If there are no matches return an empty array

## Quick Filter

Public Function QuickFilter(input_arr As Variant, col_index As Long, filter_value As Variant) As Variant
Dim r As Long
Dim Count As Long
Dim Indices As Variant
ReDim Indices(LBound(input_arr, 1) To UBound(input_arr, 1))
Count = LBound(input_arr, 1) - 1
For r = LBound(input_arr, 1) To UBound(input_arr, 1)
If input_arr(r, col_index) = filter_value Then
Count = Count + 1
Indices(Count) = r
End If
Next

Dim Results As Variant
Dim c As Long
Dim index As Long
If Count >= LBound(input_arr, 1) Then
 we want results to hold the entire row
ReDim Results(LBound(input_arr, 1) To Count, LBound(input_arr, 2) To UBound(input_arr, 2))
For r = LBound(input_arr, 1) To Count
index = Indices(r)
For c = LBound(input_arr, 2) To UBound(input_arr, 2)
Results(r, c) = input_arr(index, c)
Next
Next
QuickFilter = Results
Else
QuickFilter = Array()
End If
End Function

• I really examined this and it makes sense to me. 1. make indices w enough space in case every row hits 2. loop over input_array, storing the indices of input_array that hit, and recording count of hits. 3. make results w enough space to store count elements, 4. loop up to count populating results w rows from input_array corresponding to the values in incides. I'm still playing around with this but it feels like a good solution (or simple enough for me to understand). Feb 13, 2021 at 23:14
• I did a comparison using a dataset with 8000+ rows between a more elegant version of my function filter_arr and QuickFilter which showed QuickFilter was about 100 times faster. I guess the main point I have to accept is that looping over the data only once can look clean but redim is just such a speed bump that the code executes faster by replacing it with a combination of simpler operations. Feb 14, 2021 at 22:44
• @dactyrafficle The main thing to consider is redim preserve isn't free. It is much faster to reserve enough room in memory once (create a buffer) and then trim off the fat in the end. The same is true with strings. Feb 15, 2021 at 0:34

Based on my comment (and near terminal Covid-19 boredom) here is a starter for 10 for a class called 'FlexArray'. The code compiles cleanly and doesn't generate any untoward Rubberduck code inspections but is otherwise untested.

Usage is

Dim myArray as FlexArray
set myArray = FlexArray.Make(inputarray)

Note the Rubberduck annotations for PredeclaredId and Exposed. If you are unable to use the free and fantastic Rubberduck addin you will need to export the class to a text editor to set the relevant attributes.

'@PredeclaredId
'@Exposed
Option Explicit
' See https://excelmacromastery.com/vba-arraylist/

Private Type State

Data                    As ArrayList

End Type

Private s As State

Public Function Make(ByVal ipTable As Variant) As FlexArray

With New FlexArray

Set Make = .Self(ipTable)

End With

End Function

Public Function Self(ByVal ipTable As Variant) As FlexArray

Set s.Data = New ArrayList

Dim myRow As Long
For myRow = LBound(ipTable, 1) To UBound(ipTable, 1)

Dim myCol As Long
For myCol = LBound(ipTable, 2) To UBound(ipTable, 2)

Next

Next

Set Self = Me

End Function

Public Property Get Item(ByVal ipRow As Long, ByVal ipCol As Long) As Variant

Item = s.Data.Item(ipRow).Item(ipCol)

End Property

Public Property Let Item(ByVal ipRow As Long, ByVal ipCol As Long, ByVal ipValue As Variant)

s.Data.Item(ipRow).Item(ipCol) = ipValue

End Property

Public Function GetArrayRC() As Variant

Dim myTable As Variant
ReDim myTable(0 To s.Data.Count - 1, 0 To s.Data.Item(0).Count - 1)

Dim myRow As Long
For myRow = LBound(myTable, 1) To UBound(myTable, 1)

Dim myCol As Long
For myCol = LBound(myTable, 2) To UBound(myTable, 2)

myTable(myRow, myCol) = s.Data.Item(myRow).Item(myCol)

Next

Next

GetArrayRC = myTable

End Function

Public Function GetArrayCR() As Variant

Dim myTable As Variant
ReDim myTable(0 To s.Data.Item(0).Count - 1, 0 To s.Data.Count - 1)

Dim myRow As Long
For myRow = LBound(myTable, 2) To UBound(myTable, 2)

Dim myCol As Long
For myCol = LBound(myTable, 1) To UBound(myTable, 1)

myTable(myCol, myRow) = s.Data.Item(myCol).Item(myRow)

Next

Next

GetArrayCR = myTable

End Function

Public Sub InsertRow(ByVal ipRow As Long)

s.Data.Insert ipRow, New ArrayList

End Sub

Public Sub RemoveRow(ByVal ipRow As Long)

s.Data.RemoveAt ipRow

End Sub

Public Sub InsertCol(ByVal ipCol As Long, Optional ByVal ipColArray As Variant)

Dim myRow As Long
For myRow = 0 To s.Data.Count - 1

If myRow < UBound(ipColArray) Then

s.Data.Item(myRow).Insert ipCol, ipColArray(myRow)

Else

s.Data.Item(myRow).Insert ipCol, Empty

End If

Next

End Sub

Public Sub RemoveCol(ByVal ipCol As Long, Optional ByVal ipColArray As Variant)

Dim myRow As Long
For myRow = 0 To s.Data.Count - 1

s.Data.Item(myRow).RemoveAt ipCol

Next

End Sub

Public Property Get Row(ByVal ipRow As Long) As Variant
Row = s.Data.Item(ipRow).Clone
End Property

Public Property Let Row(ByVal ipRow As Long, ByVal ipRowArray As Variant)
' The .AddRange method cannot be used because ArrayList is a new object
' and expects an array that implements ICOllection
' VBA arrays do not implement ICOllection so the incoming array
' has to be added item by item

Dim myRowLen As Long
myRowLen = UBound(ipRowArray) - LBound(ipRowArray)

Dim myCol As Long
For myCol = 0 To s.Data.Item(ipRow).Count - 1

If myCol <= myRowLen Then

s.Data.Item(ipRow).Item(myCol) = ipRowArray(myCol)

Else

s.Data.Item(ipRow).Item(myCol) = Empty

End If

Next

End Property

Public Property Get Col(ByVal ipCol As Long) As Variant
Dim myCol As ArrayList
Set myCol = New ArrayList

Dim myRow As Long
For myRow = 0 To s.Data.Count - 1

Next

Col = myCol.Clone

End Property

Public Property Let Col(ByVal ipCol As Long, ByVal ipColArray As Variant)
' The .AddRange method cannot be used because ArrayList is a .Net object
' and expects an array that implements ICOllection
' VBA arrays do not implement ICOllection so the incoming array
' has to be added item by item

Dim myColLen As Long
myColLen = UBound(ipColArray) - LBound(ipColArray)

Dim myRow As Long
For myRow = 0 To s.Data.Count - 1

If myRow <= myColLen Then

s.Data.Item(myRow).Item(ipCol) = ipColArray(myRow)

Else

s.Data.Item(myRow).Item(ipCol) = Empty

End If

Next

End Property
`
• You have presented an alternative solution, but haven't reviewed the code. Please edit to show what aspects of the question code prompted you to write this version, and in what ways it's an improvement over the original. It may be worth (re-)reading How to Answer. Mar 25, 2021 at 16:21