LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Having Problem with "Build Matrix"

Solved!
Go to solution

Hello,

 

I am tasked with migrating an LabVIEW NXG project to a LabVIEW project and I am having trouble. My cowerker used "Read Delimited Spreadsheet (DBL)" to read from a .txt file and then converts it into a matrix using "Build Matrix". I have checked and he used "Append by column" and so did I, but when i am doing the same operations in LabVIEW not only I cannot put an indicator after building the matrix but also the matrix is not built properly.

 

More Detail: The project is to read from 2 different .txt files and transforme them seperatly into matrices (one is 1*x and the other is y*x matrices) and then substract one from another. After building the matrix and trying to put an indication, their always dashed lines going in and an error saying: "The master copy for this type definition could not be found or the master copy has errors. You must find and fix the master copy, or right-click this type definition and select Disconnect."

 

For anyone intrested here is the picture of the project where the dashed lines can be seen.

 

Diural

Screenshot 2022-05-23 144603.png

 

 

0 Kudos
Message 1 of 10
(1,361 Views)

Hi Diural,

 


@Diural wrote:

Hello,

 

I am tasked with migrating an LabVIEW NXG project to a LabVIEW project and I am having trouble. My cowerker used "Read Delimited Spreadsheet (DBL)" to read from a .txt file and then converts it into a matrix using "Build Matrix".


Why do you need to convert 2D arrays into matrixes when you can do the same operation using those 2D arrays???

Why do you initialize an array of 1001 elements just to autoindex the first 4 elements???

Why do you need to index the first element/column inside the FOR loop when you could index the first column before the loop?

 


@Diural wrote:

More Detail: The project is to read from 2 different .txt files and transforme them seperatly into matrices (one is 1*x and the other is y*x matrices) and then substract one from another.


Do you really think you can correctly subtract a 1*x matrix/2D array from a y*x matrix/2D array this way?

 


@Diural wrote:

For anyone intrested here is the picture of the project where the dashed lines can be seen.

Screenshot 2022-05-23 144603.png


What would you say when we would post an image of C source code to search for errors?

Keep in mind: we cannot debug/edit/run images in LabVIEW! Attach the real code (aka VI)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 10
(1,315 Views)

I agree with Gerd that you probably have 80% too much (and too convoluted) code. Once you attach your code, some simple data files (or equivalent simulation i.e. at least explain the sizes of the two 2D arrays!), and explain what you are trying to get out of it, we will give you a solution that fits on a postage stamp. 😄

 

I am not familiar with the term "append by column" can you explain what it does?

 

Do you have a picture of the original NXG code you are trying to duplicate?

0 Kudos
Message 3 of 10
(1,311 Views)

@Diural wrote:

After building the matrix and trying to put an indication, their always dashed lines going in and an error saying: "The master copy for this type definition could not be found or the master copy has errors. You must find and fix the master copy, or right-click this type definition and select Disconnect."

 


The dashed line IS the wire of a matrix datatype. In LabVIEW, matrix data is basically a typedef'd 2D array that substitutes special handling for some linear algebra operations. You definitely don't need that here, but I am still worried about your error. If the matrix typedef cannot be found, something is wrong with your LabVIEW installation (it is available in all versions, incl. base)

Message 4 of 10
(1,305 Views)

@Diural wrote:

More Detail: The project is to read from 2 different .txt files and transforme them seperatly into matrices (one is 1*x and the other is y*x matrices) and then substract one from another.


While it is not clear if Y or X are the number of rows, a 1*x array is just a 1D array (either by using the read function differently or by indexing out the only row or column).

 

Here's one possible way to subtract a 1D array from each row of a 2D array. Feel free to transpose, etc. if you need something else. (since you seem to prefer pictures, I am not attaching any VIs. 😄 )

 

altenbach_0-1653319092814.png

 

Message 5 of 10
(1,294 Views)

Hello GerdW,

 

I would like to say that I have been using LabVIEW only for the last couple of days thus I am fairly new to this. Maybe its the way of the forum but I found your answer as a neewbie kinda repellent but very constructive and pushed me to understand what I did wrong, so thank you for that.

 

1) I did not know that 2D arrays can be used as matrices in LabVIEW, so "build matrix" was obsolete, I have deleted them. Thus, have changed the code accordingly and will give you some detail about it.

2) The first thing that was done is to substract a 1001*11 matrix from 1001*11 matrix, so I dont have any problem and getting a 1001*11 matrix. I have checked and it works so no problem there. I am only using 4 colums of that 1001*11 matrix thus I think my coworker put the 4 so.

3) I did not understand what you wrote due to being new to LabVIEW I think so I would love to hear more, but could give some detail what I am trying to do (As much as I understand because our ex-coworker is not interested in explaining any of it): Create and empty matrix, take 4 colums of the original matrix after substraction, add all colums together and have a final 1*1001 matrix where I can draw a graph.

 

Note: I cannot give too much detail about what I am trying to do spec. because I work in an industry that requires secrecy, I know that it is making you answering this post very hard and I am truly sorry about that.

 

4) You were right, matrices were wrong, I have solved it thanks to you.

5) Again sorry for posting an image, but I do need to ask a superior if I can share more before I can (Such as a VI or required .txt files). I can replicate the code with an random txt files if it means that you can help.

 

I hope I answered all your remarks, thanks again for taking the time to answer my post. I would be happy if you have more insight that I could learn from.

 

Cheers,

Diural

0 Kudos
Message 6 of 10
(1,269 Views)

Hello Altenbach,

 Firt of all thank you for taking the time to answer me.

 

Append by column/row means that the new info that comes in will be put in a new colums or in a new row. I am pretty sure that you already know this stuff but let me give you an example; If you have append by colums enabled it will create a new column everytime a new information comes such as [1,2,3,4,5] but if you have append by row enable it will cretae rows such as

[1

 2

 3

 4

 5] Well this is what i understood from the LabVIEW help window.

I am adding the Nxg pic as you have requested below as "NXG Version"

 

As GerdW pointed out I have checked the arrays and found out I made a mistake. I have solved the mistake but the answer is still not the same. With the picture I have shared in the beginning of this post and now the NXG version of the code I am also sharing the to Graph oupputs that I am having as picture (As ı wrote to Gerd due to required secrecy I cannot share more, but if neccesary I will do my best to recreate the code so that I can share as a VI)

 

When I look at the graph it is so obvious that I am doing something wrong or I am missing something very crucial. Thank you for your welcoming repply to my post and take care.

 

Cheers,

Diural

0 Kudos
Message 7 of 10
(1,264 Views)

Hi again Altenbach,

 

The "Dashed line" answer and the array example helped me a lot. Thanks a bunch!

 

Cheers,

Diural

0 Kudos
Message 8 of 10
(1,262 Views)
Solution
Accepted by topic author Diural

@Diural wrote:

I would like to say that I have been using LabVIEW only for the last couple of days thus I am fairly new to this. Maybe its the way of the forum but I found your answer as a neewbie kinda repellent but very constructive and pushed me to understand what I did wrong, so thank you for that.


I am sorry to hear that your company is throwing you into the deep without giving you some swimming lessons first. There are plenty of good learning resources listed at the top of the forum, and I strongly recommend to go over them. Graphical programming is quite different from text programming (... and much more fun!) and requires significantly different skills that you cannot carry over from text based programming.

 


@Diural wrote:

1) I did not know that 2D arrays can be used as matrices in LabVIEW, so "build matrix" was obsolete, I have deleted them. Thus, have changed the code accordingly and will give you some detail about it.


2D arrays are 2D arrays and matrices are matrices! While they can carry the same data, they are treated very differently. For example if you multiply two 2D arrays, the multiplication occurs element by element (And the smaller size wins). If you multiply two matrices, you get a matrix multiplication (very different result!!!) or nothing at all if the sizes are not suitable. To avoid confusion., never call 2D arrays matrices. The matrix datatype should exclusively be used for linear algebra problems.

 


@Diural wrote:

2) The first thing that was done is to substract a 1001*11 matrix from 1001*11 matrix, so I dont have any problem and getting a 1001*11 matrix. I have checked and it works so no problem there. I am only using 4 colums of that 1001*11 matrix thus I think my coworker put the 4 so.

 


OK, so the problem description has changed dramatically and the two 2D arrays (NOT matrices!!!!) match in size. Wiring 4 to the FOR loop will give you four rows, not four columns, so make sure yo get what you want. All you probably need is take an array subset of four columns. No loop needed. No initialized array of zeroes needed!

 


@Diural wrote:

 

3) I did not understand what you wrote due to being new to LabVIEW I think so I would love to hear more, but could give some detail what I am trying to do (As much as I understand because our ex-coworker is not interested in explaining any of it): Create and empty matrix, take 4 colums of the original matrix after substraction, add all colums together and have a final 1*1001 matrix where I can draw a graph.


OK, so you have four columns and want to take the sum, ending up with a 1D array. All you probably need is the following.

 

altenbach_1-1653401233421.png

 

If done right, the entire processing could probably done with much less code. Notice that you have all that duplicate code reading the two files. All you need is one instance, autoindexing on an array of file paths using a FOR loop. Half the code right there!

 


@Diural wrote:

I can replicate the code with an random txt files if it means that you can help.


Yes, that would be all we need. 

 

 

Message 9 of 10
(1,254 Views)

@Diural wrote:

 

Append by column/row means that the new info that comes in will be put in a new colums or in a new row. I am pretty sure that you already know this stuff but let me give you an example; If you have append by colums enabled it will create a new column everytime a new information comes such as [1,2,3,4,5] but if you have append by row enable it will cretae rows such as

[1

 2

 3

 4

 5] Well this is what i understood from the LabVIEW help window.

I am adding the Nxg pic as you have requested below as "NXG Version"

 

NXG_Version.jpeg

 


 

Well, this code is quite poor too. So maybe whoever wrote this code and refused to explain it to you is not really qualified do all this either 😞 . There is no need to initialize any array or even use a shift register if you correctly transpose and subset the array first.

You are not "appending" anything. That terms only makes sense if you have more than one input.

Wiring [i] to an index array function is the same as autoindexing, so all this is pure Rube Goldberg.

 

 

0 Kudos
Message 10 of 10
(1,249 Views)