From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create matrix

Hi,
I have 4 1D array and want to create a 2by2 matrix. In each iteration a 1D array will multiple with the matrix(vector multiple a matrix). 
 
Please advice.
 
 
0 Kudos
Message 1 of 12
(10,796 Views)
Hello,
 
Attached is an example showing how you can build a 2D array (matrix) from four 1D arrays using the Build Array function (it makes rows out of the input 1D arrays to create the 2D array), and then multiply the result by a 1D array (vector).  I have shown the vector as column vectors so that the operation is/appears more closely correlated with what is required by matrix multiplication - that the number of columns in a matrix A must be equal to the number of rows in matrix B, if indeed the matrix multiplication AxB is to be defined.
 
In any event, this should give you an example of the kind of operation you'll need to do in your loop to achieve your desired functionality!
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
0 Kudos
Message 2 of 12
(10,769 Views)
Here's a copy of the VI attached above, only with default values saved so you can simply run it when you open it 🙂
 
Best,
JLS
Sixclear
0 Kudos
Message 3 of 12
(10,766 Views)

Hi JLS, Thanks for replying. It has helped me feel that i am learning in the right direction.

Say i will need to display my results for every loop iteration, should i use shift register or stacked shift registers for my case?

I realised that the uses of the For Loops are very tricky. i have been trying to look for examples but still doesnt know how to use them.  Any application notes to recommend?

Attached is an example i created. Please advise me the mistakes i am getting.

Many Thanks

0 Kudos
Message 4 of 12
(10,748 Views)
Hello again,
 
You will want to use shift registers only if you care to have values you compute in a given iteration be available to you in a subsequent iteration.  I think you can use the build array function one time outside your loop, and then simply index the array or "replace array subset" as necessary using the array functions or auto-indexing.  If you use auto-indexing at the input (ie. wire in an array) with a 2D array, you'll be pulling off rows at each iteration... if you want columns you can always use the 2D array transpose function from the array palette before wiring the array to the for loop.  Now, if you need to compute and modify the 2D array inside, and then use the modified version in the next iteration, you can use a single shift register to hold the 2D array, where if you pass the array to the shift register on the right, it will be available to you on the left on the next iteration.
 
Ok, I think that's what you are looking to do in general.  If not, can you be more specific about precisely what you would like to do... something like:
 
1. initialize a 2D array
2. in a loop, multiply the 2D array by a vector, where the 2D array and the vector changes each iteration, and display the 2D array and vector
 
 
To do what is suggested above, simply create a shift register on a for loop and wire the 2D array built from the 1D arrays to it (on the outside of the for loop).  Also wire your vector to a shift register outside your loop.  These are the first values your loop will use.  Inside the loop put whatever code you want to operate on the array and vector, multiplying them before or after that code in the loop as necessary, and then wire the new array and vector to their respective shift registers on the right side of the for loop.  You can create an indicator on the wires just before the shift registers to display the data on each iteration!
 
Ok, I hope this helps you!
 
Thank you,
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
0 Kudos
Message 5 of 12
(10,732 Views)

Hi JLS,

Thanks for your explainations.

I had followed your advises and created these.Please take a look and give me some comments on the errors.

I got a feeling  i would not need to use shift registers.

Many thanks.

0 Kudos
Message 6 of 12
(10,715 Views)
Celynn,
 
A few things you should keep in mind when doing multidimensional calculations is the dimension size.  It seems like a lot of the broken wires are due to trying to do an operation on a 2-D array when the VI is looking for a 1-D array.  Also I will reiterate that the purpose of shift registers is to pass information from one iteration of the for loop to the other, so unless you need that information in the next loop, you do not need the shift register.  Lastly, it may seem silly, but make sure that the VI terminals are actually connected and not just wired straight underneath the VI.  Hope this helps!
 
Andy F.
-----------------------------------------------------------------
National Instruments
0 Kudos
Message 7 of 12
(10,700 Views)
If you want to perform matrix-vector product iteratively, you may simply move the "A X B.vi" into the FOR loop.
I create a simple VI for your reference (I use LV 7.1). Hope this is helpful.
If you want to get the result of each iteration, you only need to extract the corresponding row of the resulting matrix.
0 Kudos
Message 8 of 12
(10,696 Views)

Hi, I know this is an old thread, but I've got a problem which keeps leading me back here.

 

I've got 2 vectors, one X by 1 the other 1 by Y.

 

I want to multiply them them to get one matrix of X by Y dimensions.

 

ie (in Matlab)

x=1:10

y(1:5)=1

y=y'  (rotate array)

y*x=     1     2     3     4     5     6     7     8     9    10  

1     2     3     4     5     6     7     8     9    10     

1     2     3     4     5     6     7     8     9    10     

1     2     3     4     5     6     7     8     9    10     

1     2     3     4     5     6     7     8     9    10

 

When I try this in Labview with the multiplication VI I only get a single integer output whichever way I wire it.

 

Hope you can help

0 Kudos
Message 9 of 12
(9,639 Views)

Look for the Outer Product VI under the Linear Algebra palette.

0 Kudos
Message 10 of 12
(9,629 Views)