LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to index two points in csv matrix and add them together?

Screenshot 2023-08-09 at 12.42.45 PM.png

Hi all, I'm having trouble understanding how to work with matrix and array functions.

I have matrix in a csv file I've attached and I need to essentially add column A to column B then have it display to my indicator.

More specificially, if I have [1,2,3;4,5,6] what I am wanting is 1 + 2 = 3

and then the code needs to go down to the next row and do the same thing: 4 + 5 = 9

and display each sum one at a time for x amount of time.

I'm just really lost and not sure what I need to do.

I have it all inside of a case structure and button because when its in 'manual mode' I'm supposed to be able to add x and y and have it display to the same indicator I mentioned before. whereas the 'automatic' mode will pull from the csv and automatically perform the addition functions and display the sums for me.

Any help on this would be appreciated.

0 Kudos
Message 1 of 8
(1,302 Views)

Screenshot 2023-08-09 at 2.11.45 PM.png


Hey guys,  I got some help so this is a much better version of my code. Only a few things however.

I want my button to run the portion of the code that operates with the arrays.

I also want the values to start from the beginning of the CSV file when i activate teh button.

RIght now in this current configuration, when the csv file is running, switched to the other mode, then back, it starts where it left. 

0 Kudos
Message 2 of 8
(1,280 Views)

Hi tompm,

 


@tompm wrote:

I got some help so this is a much better version of my code.


This is not "code", this is just an image of code.

Remember: we cannot edit/debug/run "images of code" with LabVIEW!

(When attaching code you should downconvert to an older LabVIEW version so more active members can actually access the code. I prefer LV2019.)

 


@tompm wrote:

I want my button to run the portion of the code that operates with the arrays.

I also want the values to start from the beginning of the CSV file when i activate teh button.

RIght now in this current configuration, when the csv file is running, switched to the other mode, then back, it starts where it left.


Which "button"? There is no "button", but only "manual" and "stop"…

When you want to start from beginning then you should not use the loop iterator to index rows…

 

  • Why do you read the CSV file as strings when you want to add numbers later on? Why not read as numbers/floats???
  • Why don't you use AutoCleanup before posting?
  • Why do you wire 0/1 to index the first two columns? It's not needed!
  • StringToDecimalNumber also works with arrays so (maybe) you don't even need to index the column data…
  • Have you learned how to use shift registers? You will need them for your task…
  • What is a "csv matrix"? CSV files (typically) contain 2D array data! (A "matrix" is a different datatype than a simple 2D array in LabVIEW…)
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 8
(1,240 Views)

Hi, GerdW,

Thanks for letting me know I should attach my code instead of using images. I apologize, I am new to this forum.

I would downgrade my code, but unfortunately I suffer from technical complications on NI's side that leaves me stuck with the version I have now which is the latest version (2023 Q3).

Yes, I meant my manual button.

Gotcha, I will not use the loop iterator to index rows. I understand now how that could prevent me from starting at the beginning of the file.


  • Why do you read the CSV file as strings when you want to add numbers later on? Why not read as numbers/floats???

I had help from someone and they were less concerned with the small details and focused on getting the code to do what I want. It's up to me now to workout the details. I will figure out how to implement this change.

  • Why don't you use AutoCleanup before posting?

Apologies, I am not familiar with what that is. I'm assuming it's a function of some sort that cleans up my wires and spacing?

  • Why do you wire 0/1 to index the first two columns? It's not needed!

its not? I did not know that thank you. I just removed them and I see now my code is doing the same thing still.

  • StringToDecimalNumber also works with arrays so (maybe) you don't even need to index the column data…

I will look into removing the index function.

  • Have you learned how to use shift registers? You will need them for your task…

I just learned how to use them a couple weeks ago. I'll look into implementing this method.

 

  • What is a "csv matrix"? CSV files (typically) contain 2D array data! (A "matrix" is a different datatype than a simple 2D array in LabVIEW…)


apologies for my verbiage. My csv file is an array I made in excel that has 3 columns and 21 rows of data.

I am now having an issue where I click my 'automatic' button and it's supposed to stay latched but becomes unlatched after 1 iteration.

To give you more context, I will give you the goals I am trying to accomplish with my code:

 

  • Create a latching button label “Automatic: Read from CSV”.
  • When the button is unlatched, the x and y inputs sum will display on the 'sum' indicator
  • When “Automatic: Read from CSV” is latched, add values from column A and column B of the CSV (should be updating once a second).
  • Have automatic mode ignore x and y inputs and instead add columns a and b from CSV file and display 1 box at a time the sums from each box.
  • Hint: you’ll use the “select” block in Labview for the different modes. 
  • Hint 2: use local variable to make your code cleaner.


This time I've attached my code with the CSV file. Here's a screen shot of it too just incase.

 

Screenshot 2023-08-15 at 11.09.52 AM.png

 

Download All
0 Kudos
Message 4 of 8
(1,201 Views)

Hi Tom,

 


@tompm wrote:

I would downgrade my code, but unfortunately I suffer from technical complications on NI's side that leaves me stuck with the version I have now which is the latest version (2023 Q3).


There is no menu entry File->Save for previous available in your LabVIEW installation?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 8
(1,197 Views)

OH!

I didn't realize that is what you meant. I thought you meant I needed to literally install an older version. I did not know you could also save as previous version! So sorry for confusion. I'm obviously very new to labview, I hadn't even heard of labview until 2 months ago now I'm learning it for my internship project!


I've attached the 2016 version!

 

Edit: I also added the 2019 version since you said you prefer it!

Download All
0 Kudos
Message 6 of 8
(1,192 Views)

Hi Tom,

 

see this simplification:

Does (nearly) the same as your VI…

Best regards,
GerdW


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

thanks for the simplification.

I just tried it myself, and I see what you mean by (nearly).

However, now the automatic button isn't working at all in this version.

Everything else seems fine, just need help figuring out how to make the button activate the csv file from the beginning and start adding colums A and B.

I think the original intent/purpose I had with the 1 and 0 constant was that that was effectively grabbing my column A and B from the csv and then summing them.

How do we go about doing that with this set up?

0 Kudos
Message 8 of 8
(1,179 Views)