LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert a scalar variable into a 1-D length N array?


nano3528 wrote:

Thanks for all the replies!

 

I tried using the 'write to speadsheet' function last night but I the output it always an empty file. This is puzzling. When I try wiring anything to 'build array' and then to 'write to speadsheet', there are no errors, but there's no output.  I tried with and without 'build array'.  I build the array in the for loop. I'm just trying to see if I can build an array of input values for now. Why wouldn't this work? I've attached a snapspot of the block diagram: 'Write to speasheet' on the upper right corner with delimiter controls and a path indicator. 


I don't believe you need that build array function before the indexing in your for loop (you can see it in the upper left corner of your attached .jpg). Just trying to help out 🙂 I believe the tunnel will build the array for you.I don't believe this answers your question lol, but its just something that you shouldn't worry about when debugging.

Message Edited by for(imstuck) on 03-03-2009 03:30 PM
Message Edited by for(imstuck) on 03-03-2009 03:31 PM
0 Kudos
Message 11 of 23
(2,046 Views)

Dennis Knutson wrote:
Have you done any basic debugging? Place a probe on the output of the for loop. Place a probe on the output of the case structure. Do you see any data? You should also know that the way you have wired the data out of the case statement, the false case will output an empty array.

Probably what is happening is the case is switching to false, not true. Have you highlighted execution? If the code isn't getting to your for loop in the true case, but is instead just passing through the empty false case, you will be sending an empty array. 

Message Edited by for(imstuck) on 03-03-2009 03:37 PM
0 Kudos
Message 12 of 23
(2,040 Views)

I just tried the highlighted execution... I was making a mistake with one of my connections. Thanks for the tip. Now it works, mostly.

 

I'm trying to convert a string of the form 'xxxx-1.9958378' where the first four entires are letters and the final entries are number digits. I looked at string to number function, but it outputs a zero I think because the letters are not acceptable as inputs. Then I looked at hex to double and that did not work either. Suggestions? Basically, I'm trying to write a string to a text file, and in order to do this I've seen that I need an array to input into the 'write to spreadsheet' function. This works well, because I have an array of current outputs of the form 'xxx....' as described above. 

0 Kudos
Message 13 of 23
(2,021 Views)
You are trying to write what string? Is it the output of the GPIB Read? If so, why are you trying to convert to a number? If you want to save the whole string, convert the numeric data you alrady have to a string, append them together with the Build Array and wire the string array to Write to Spreadsheet file. If you have an older version of LabVIEW, there are directions on the block diagram on the necessary modifications.
0 Kudos
Message 14 of 23
(2,012 Views)

I have LabView 8.6, I don't think it's old.   

 

If you look at that diagram somewhere on page 1 of this thread, the output I am looking at is from 'Read Message' sub-VI, so I guess it's the GPIB read.  It's of the form 'NCDI+1.99589353mA' just incidating a current value. I want to build an array of these outputs and then write them to a spreadsheet. To write to a speadsheet, I need an array, and the input to 'build array' is a double, but I have a string. are you saying that I can change the build array function to take a string as the input? That would be helpful. I don't have LabView in front of me anymore, but if that's the case then I'd try it.

0 Kudos
Message 15 of 23
(2,006 Views)

You've got an array now though the use of the Build Array inside the for loop makes no sense at all. Get rid of that and you have a 1D array. Convert that to a string array. Wire that to a Build Array. Wire your single string from the GPIB Read (this is NOT an array) and then wire the output of the Build Array to the 1D input of Write to Spreadsheet file set for strings.

 

Instead of some partial images, why don't you just post the actual VI?

Message 16 of 23
(1,992 Views)

I'm not always at a computer that has LabView installed on it, so I save snapshots to post on this forum.

 

The VI is now attached. I know the GPIB read is not an array. I'm  assuming here that the GPIB read is the output of 'Receive Message' in the program.

 

It's not the most efficient output right now, but I have one file for the voltage values, and one file for the lone current value.  I'm in the process of trying to figure out how to parse every value sent to that 'received message' sub-VI so I can save all the data. 

0 Kudos
Message 17 of 23
(1,975 Views)

I don't know why, but edit wasn't working.

 

Look at this file instead... I just have to figure out how to get each current value corresponding to a voltage value. Otherwise, everything works.  

0 Kudos
Message 18 of 23
(1,967 Views)

You show some very inefficient coding practices. Who wrote these subVIs? Why are the inputs on the right? You are building a voltage array, indexing it into a FOR loop and indexing it back out unchanged? Why? Unless you only have LabVIEW base, there is a ramp pattern tool. I would also think writing the files should go inside the case. Why would you want to write to a file if the case did not execute to generate any data?

 

If you want to read a message after each voltage update, things belong into the same loop. Maybe you could do something like in this picture? (Sorry, I don't have your subVIs, that why the show as "?").

 

 

Now, if you want to write each voltage/current pair into a single 2D file, just make a few modifications.

Message Edited by altenbach on 03-03-2009 09:19 PM
Message 19 of 23
(1,958 Views)
Thanks for clearing all of that up! Do you know if the ramp function would prevent a problem dealing with timing that the primitives would not?
0 Kudos
Message 20 of 23
(1,928 Views)