From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Matrix - sum of elements under/above main diagonal

Solved!
Go to solution

I tried to add the elements from the main diagonal with this code ( replace < with = ) and it works...If I use < or > the code won't work and I saw that it depends which element from the index ( inside the second for ) I add .Can someone explain me why it depends which element I add ? Why are there 2 elements in the first place and not one element with the i,j coordinates ?

I want an answer for this solution,I'm not interested in other much simpler solutions.

How can I make THIS code easier ?

Download All
0 Kudos
Message 1 of 6
(3,750 Views)
  • Before attaching code, fill the matrix control with typical values and make them the default. An empty matrix means more work for us and we have to make assumptions, e.g. Is the matrix square?
  • Always save a VI under a reasonable name related to the problem. Over time, my downloads folder contains so many "untitled 1.vi" files that I am up to "utitled 1(10).vi. now. This often breaks things, for example if a subVI is named this way, the caller most likely calls some stale old VI. 

 

 

Regarding your problem, try some debugging steps, for example place some probes or use execution highlighting. Slow down the loops and add extra indicators, etc.

 

Since you are autoindexing on the outer loop, you only have a 1D array inside the inner loop and you are indexing out two neighbors. If you would disable indexing on the outer loop input, you'll get a 2D array and can get a single element based on the two indices. Do some tutorials!

0 Kudos
Message 2 of 6
(3,737 Views)

@dafuq313 wrote:

I want an answer for this solution,I'm not interested in other much simpler solutions.



@dafuq313 wrote:

 

How can I make THIS code easier ?


You are contradicting yourself. Easier is always simpler. The explanation is at the end of my previous post. You need to understand autoindexing and arrays. Once you understand it, the code boils down to this.

 

 

 

 

 

0 Kudos
Message 3 of 6
(3,719 Views)
Solution
Accepted by topic author dafuq313

@dafuq313 wrote:

I want an answer for this solution,I'm not interested in other much simpler solutions.


Here's how to program your solution correctly. (of course since the matrix is always square, we only need to get one of the dimensions...)

Message 4 of 6
(3,700 Views)

Thank you for answers,I was trying to say that there are easier solutions ( withouth 2 fors ) and I didn't want one of those.

I couldn't find proper tutorials for labview since is not that much used...

Thank you very much 😄

0 Kudos
Message 5 of 6
(3,646 Views)

Even my simple solution has two FOR loops. 🙂

0 Kudos
Message 6 of 6
(3,627 Views)