LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using for loop to create an off diagonal elements

Solved!
Go to solution


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 22
(344 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 22
(337 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 22
(321 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 22
(311 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 22
(267 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 22
(259 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 22
(228 Views)

@Rusyaidi_arif_cute wrote:

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.


That's not really "simpler", just more confusing. How big is the 1D array and how does its size depend on the size of the 2D array? What is the meaning of "vice versa" and "and so on". Very ambiguous! Does each element of the 1D array go into multiple places? 

 

You also need to be very careful with terminology. For example the word "add" mathematically means to add the new element to the existing element at the desired location. Colloquially, it could also mean to "replace" the current element with the new value.

 

In simper terms, why not just describe the desired result.

 

For example if the 2D array is

 

A B C D
E F G H
I J K L
M N O P

 

 and the 1D array is:

 

Q R S T

 

 

How should the result look like?

 

 

0 Kudos
Message 8 of 22
(216 Views)

I see I need to be careful with the terminologies as well but sorry for the confusion. I really meant add as in mathematical addition.
The size of 1D array depends on maximum no. of input rows
The Maximum size of 2D array depends on maximum element inside "nr" or "nl" of my original code.

Rusyaidi_arif_cute_0-1737537397338.png

 



The results will look like this
where A, F, K ,P = 0.
D H M N = any number. In this case is 0.

A  B+Q  C+R D
E+Q F   G+S  H
I+R J+S  K   L+T
M   N   O+T  P

 

0 Kudos
Message 9 of 22
(212 Views)

 

So, what are the rules??

:

  • If the 2D array is NxN, what is the size of the 1D array?
  • What are the general rules where these values are added?

 

Do you have a link to a website that describes the math and purpose behind this exercise?

0 Kudos
Message 10 of 22
(191 Views)