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: 

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

Hi guys,

I am new in Labview. I use Labview to accquire the output data from a measurement circuit with RS232 bus. The result needs some mathematical operation to have a meaningful number. After this operation the result is a scalar variable that is changing as new data read from my circuit. I want to see the power spectrum of this signal so tried to use FFT block (Labview 6.1, signal processing->frequency domain->real fft / power spectrum). However because the fft block needs 1-D array type of data as input, I can not just connect my result to the fft block. The error it gives me is:

These cannot be wired together because their data types (numeric, string, array, cluster, etc.) do not match. Show the Context Help window to see what data type is required.
The type of the source is double [64-bit real (~15 digit precision)].
The type of the sink is 1-D array of double [64-bit real (~15 digit precision)].


So I guess I have to do something to convert my result into a 1-D array with a length N, which is the number of data I use for one FFT transform. But the question is how.
I pass the data directly through a For-loop, the result is a 1-D array with all the members having the same value as the input value(my calculated result). Then next time a new result come in, all of the members of that array changes to the new value.

Please help!
0 Kudos
Message 1 of 23
(4,087 Views)
Hi Jia,

create a shift register in your while loop, use a "build array" node to add your single measurement values to the shift register to create an array of all values. This array can be wired to the fft function...

And please take part here!
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 23
(4,080 Views)

I'm having the same problem ... sort of. I want to convert a 1-D array of length N to a double... or I guess to better phrase this, pass each value of the 1-D array into a VI where only one value can be input at a time. To put in context, I'm trying to do a voltage sweep from -2 to 2 volts. I made a for loop that will have N voltage steps between -2V and 2V. The error I get when I wire the output of the loop directly to the scalar input is (I knew I would have an error before doing this)...

 

"You have connected an array data type to its element data type. This type conflict may be resolved by indexing the array to access individual elements of the array. Check for a tunnel on a loop that has indexing incorrectly enabled.
The type of the source is 1-D array of
double [64-bit real (~15 digit precision)] [numFlags=0x0].
The type of the sink is double [64-bit real (~15 digit precision)] [numFlags=0x0]. "

 

Does anyone know how to index the array to accomplish this? I think this would be easy, but I couldn't find anything to do it. I could upload a picture of the block diagram if that would help. Any help would be greatly appreciated.  

0 Kudos
Message 3 of 23
(3,902 Views)

Hi nano,

 

have you tried to put the subvi into a (FOR) loop? Then autoindexing of the array will do the rest automatically Smiley Wink

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 23
(3,900 Views)

GerdW,

 

Thanks for the fast reply. I've included a picture of the block diagram because I want to be certain about what you were saying... So I interpret that as putting the for loop (the subVI) in another for loop? Or are you talking about the 'vsource control' block?

 

 

 

 

 

 

 

 

 

0 Kudos
Message 5 of 23
(3,896 Views)

Hi nano,

 

"So I interpret that as putting the for loop (the subVI) in another for loop?" - Yes, correct.

See example! (Also on better using LV primitives.)

 

Where is this "vsource control block"?

Message Edited by GerdW on 03-02-2009 11:24 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 23
(3,884 Views)

GerdW,

 

Thank you. That example was extremely helpful!! If I wanted to save this data as it was being processed, would I also include the write to text subVI inside that loop with the other subVI?  

 

Sorry, I think I am using wrong labview vocabulary... in the PNG file I attached, 'VSOURCE CONTROL' is within the case structure. It is where the output of the original for loop I made was connected to

Message Edited by nano3528 on 03-02-2009 08:41 PM
0 Kudos
Message 7 of 23
(3,866 Views)

Hi nano,

 

"would I also include the write to text subVI inside that loop with the other subVI?"

 

Well, in general you could.

BUT: writing single values to a textfile would create a lot of overhead (file open, seek, write, close) in each iteration.

When your arrays are rather small (less than ~10 million values on a modern PC) you could go with arrays and the spreadsheet functions (either string palette "array to spreadsheet string" or file palette "write to spreadsheet file").

 

Ok, now I spotted the "vsource control" - it's your subvi. Usually I don't refer to text in the icon of a subvi, so I didn't notice it...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 23
(3,847 Views)

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. 

0 Kudos
Message 9 of 23
(3,822 Views)
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.
Message 10 of 23
(3,811 Views)