LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get inputs (in number) from external text file to run a mathematical equation with each input?

How to get inputs (in number) from external text file to run a mathematical equation with each input?

Get VI to read from a file that contains multiple radii (i.e., each line in the file should contain one radius) . The front  panel should allow the user to input the specific the number of radii contained in the file.
The VI should:
1.Get the user input (the number of radii in the file;
2.Open the file;
3.For each radius in the file, the VI should calculate the volume of the sphere and write it to anew line in an output file called volumes.txt

 

Please if possible upload an example.
.

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

Yes you can do it.

 

  1. Use File I/O functions to read your text file.
  2. Write your logic to calculate volume (Use Numeric functions/Formula nodes)
  3. Save the result in new other text file (use File I/O function).

 

Try & post your code. Ask if your facing problem.

Munna
0 Kudos
Message 2 of 10
(3,814 Views)
The problem is that in a text file there is a list of numbers listed. And I need to use each number to calculate a volume. I don't know how to get the first line and then next line and etc.
0 Kudos
Message 3 of 10
(3,805 Views)

If your file size less, read your data at once (using Read From Speadsheet File vi). You will get array.

Get that array & use For Loop to calculate volume.

Munna
Message 4 of 10
(3,801 Views)

Thank you, but I still don't know how to make it to read all data, and run vi to find all volumes without me identifing which row to read.

0 Kudos
Message 5 of 10
(3,737 Views)

Is this homework?

 

You've been given all the information you need to get started.  If you don't know how to act on that info, then I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 6 of 10
(3,730 Views)

Have you even tried doing what he suggested?  If so, why haven't you posted the VI to show where you'er getting stuck.  If not, of course you don't know how to make it work.

0 Kudos
Message 7 of 10
(3,723 Views)

just to make mure that I actually did tried his suggestion.and I'm stuck here. I can save data one by one by telling it which row (or after how many charechters) to read and then write. I can't make it to read all and write all volumes.Untitled.jpg

0 Kudos
Message 8 of 10
(3,712 Views)
Please take the time to take some of the free tutorials. You only have a single value because that is what you have coded. Take the array from the Read From Spreadsheet and wire it into a for loop. Each line will be auto-indexed, line by line. Process each value inside the loop. Wire the result out of the loop. Each value will be auto-indexed into an array. Write the array.
Message 9 of 10
(3,696 Views)

Dear azhiqaradaghi

 

Read your data at once (if file size is less). Based on your input file, you need to define delimiter (most of the cases “comma”) & no need to provide any other parameters (offset n all). You will get 2D array as output.

 

From 2D array, get your required data (using index array).

Pass your 1D array (output of index array) to For Loop & calculate Volume for every value. Take the For loop output & write it to file.

Munna
Message 10 of 10
(3,685 Views)