LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiplying each element of 1D array by different numbers

Solved!
Go to solution

Hi,

 

Does anyone know how does multiplying elements of 1D array work? I need to multiply every element of an array with 8k elements by its index, so I tried with a For loop, wiring the array with the loop iteration counter but it seems to be wrong. Any suggestions? Thanks!

0 Kudos
Message 1 of 7
(351 Views)

You need an autoindexing output tunnel.

 

Even then, I think we need more context to give you any real advice.  Where is the 2D array coming from?  Do you also need a 2D array output?  What is that being used for?  What algorithm are you trying to implement?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 7
(341 Views)

Your code does exactly what you need. what is wrong with that ? 

0 Kudos
Message 3 of 7
(324 Views)

I am sorry for not giving more context of the situation. So, I am making a program that is calculating the phase difference received from 2 antennas and after finding it, using some math formulas to find the Theta angle which I use to calculate the height of an object caught by the receiver antennas. The 2D array in the diagram is actually 1D array with only 1 row with information and 8118 columns - it is the Theta Angles in every bin. I do not really need 2D output. In fact it doesn't matter, it is just a way of displaying, isn't it? I need to multiply every element of that 2D array (with only 1 row of information), by its index - for example :

{ 5, 17, 42, 0.3, 7, 9, 1, 2214.433 } =

{5*0, 17*1, 42*2, 0.3*3, 7*4, 9*5, 1*6, 2214.433*7 }

etc...

I really cannot find a way of doing this except making a c++ .dll and import it. 

 

P.S: I did some edit of the VI to remove other rows that i do not need.

0 Kudos
Message 4 of 7
(322 Views)
Solution

You you seem to have all 1D arrays represented as 2D arrays with one column. That's unnecessary.

Your phase calculation would be trivial by just using complex math. No need to jump trough flaming hoops detecting quadrants. (You could also use the two input atan, of course). I am pretty sure your code does not do what you think it does.

 

I think most of your code is extremely convoluted, but since we can't see many things in a truncated picture, we can only guess. For example your parallel FOR loop repeats the exact same calculation thousands of times for no obvious reason. Please attach a simplified version of your code and make sure it contains some typical data. (Also do a save for previous (2020 or below before attaching).

 

Done right, the entire algorithm would probably fit on a postage stamp. 😄

0 Kudos
Message 5 of 7
(309 Views)

An obvious improvement would be to use a 1D array instead of a 2D array with only 1 row. You can use an Array index primitive for that. That way your code from the 1st post would simply work. You could also remove the For loop counter and let auto-indexing do its thing

 

On another note the For loop labelled "Calculating Phase" is of no use because you are not using the index. The compiler might be smart enough to execute only once.

0 Kudos
Message 6 of 7
(295 Views)

@RamonG wrote:

On another note the For loop labelled "Calculating Phase" is of no use because you are not using the index. The compiler might be smart enough to execute only once.


The most glaring issue is that the quadrant detection must be per point in the most general case (because the data could easily span several quadrants), but the current code bunches all data together. Only complex math (or the two input atan) can work globally on arrays (no loop!). For an example have a look at my talk (Part II, slide #10 here).

 

Except for the ugliness, having 2D arrays with one column is quite similar to 1D arrays under the hood. The elements are adjacent and the cost is only four bytes for the extra dimension info in the header. Still, 2D arrays unnecessarily  complicate the indexing.

0 Kudos
Message 7 of 7
(269 Views)