LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using for loop to create an off diagonal elements


I only need to get the output to show an off diagonal elements like this,

Rusyaidi_arif_cute_2-1737480654162.png

formula to get off diagonal:

nbr=3

 

Rusyaidi_arif_cute_5-1737481011560.png

 



Here is what I did.

Rusyaidi_arif_cute_3-1737480841687.png

Rusyaidi_arif_cute_4-1737480854918.png

a 3 by 3 output by using the 1d array and zeros (3by3)

To be fair i am not sure what i was doing here because i was just trying out everything and could not understand. Hopefully, someone can help me. I have attached the file.

 

0 Kudos
Message 1 of 7
(122 Views)

 


@Rusyaidi_arif_cute wrote:


I only need to get the output to show an off diagonal elements like this,

Rusyaidi_arif_cute_2-1737480654162.png

formula to get off diagonal:

nbr=3

 

Rusyaidi_arif_cute_5-1737481011560.png


 

I don't understand your formula, because 2D arrays have two indices, not just one (k).

 

You have two array constants, which one would you like to process?

Your 2D arrays are not square, so the concept of "diagonal" is poorly defined.

Given the default input, what would be the correct result?

Why would you need to spin that loop millions of times per second doing the same thing over and over?

 

Are you aware that index array is resizable? Compare these two fragments:

altenbach_0-1737482254526.png

 

 

 

Message 2 of 7
(115 Views)

For starters, I did know it was resizable but didn’t know the function for it. Im surprised it could get much more simpler and less blocks than before!

The while loop all over it was just me trying to understand what it does to everything. Forgot to remove it.

The constant k in that formula refers to a number in the specified row,column vector for example Y(1,2) would represent an element of row 1 and column 1

 

Y=[Y(1,1) Y(1,2) Y(1,3)

     Y(2,1) Y(2,2) Y(2,3)

     Y(3,1) Y(3,2) Y(3,3)]

 

I want to make the diagonal part to be 0.

I cant seem to understand how to.

 

1d Array is my input Y(k)

whereas Y(zeros) are just Y (3by3) with all zeros in it.

sorry for bad english.

0 Kudos
Message 3 of 7
(99 Views)

@Rusyaidi_arif_cute wrote:

I want to make the diagonal part to be 0.

.


Maybe like this?

 

altenbach_0-1737484205496.png

 

Message 4 of 7
(89 Views)

Yes thats how i want to create thank you so much! I will try to do it with my input.

0 Kudos
Message 5 of 7
(45 Views)

That's one of the objective done, another thing is how would I do it if for example in your case,
(4 by 4) array were added with a 1d array
1d array:- [1
                  2
                  3
                  4]
To make it simpler my formula takes an element from each row of 1d array for example the first row  =1, and then 
it will add with an element inside (4by4) array,  in row 1, col 2 ,vice versa so it would be Y(1,2) & Y(2,1) of the array. The second row of 1d array=2, will add onto another element of Y(2,3)& Y(3,2) and so on.

0 Kudos
Message 6 of 7
(37 Views)

Hi Rusyaidi,

 


@Rusyaidi_arif_cute wrote:

another thing is how would I do it if for example in your case,
(4 by 4) array were added with a 1d array
1d array:- [1
                  2
                  3
                  4]
To make it simpler my formula takes an element from each row of 1d array for example the first row  =1, and then 
it will add with an element inside (4by4) array,  in row 1, col 2 ,vice versa so it would be Y(1,2) & Y(2,1) of the array. The second row of 1d array=2, will add onto another element of Y(2,3)& Y(3,2) and so on.


Just implement your calculations, using a loop with a shift register and some array functions (like IndexArray and ReplaceArraysubset).

(Once you have done so you may learn about the InplaceElement structure and how to use it with array data…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 7
(6 Views)