# LabVIEW

cancel
Showing results for
Did you mean:

## Writing data from two while loops to an Excel sheet

Hello everyone,

First of all, I started to use Labview two months ago so I`m a total beginner.

Now the challenge:

In general, I want to stimulate the muscles of the forearm to measure the resulting angle of the wrist-based on the stimulation intensity. So higher stimulation amplitude leads to a larger wrist angle.

Therefore, I use two while loops. One is calculating the stimulation intensity which should be increased every second (1 Hz). The second is about measuring the wrist angle of the wrist using a goniometer with a sample rate of 100 Hz.

While executing the program, I want to save the data into an Excel file to relate stimulation intensity/ voltage and resulting wrist angle. But when I pass the data out of the while loops to the Excel sheet, the resulting format is a 2D-array for each loop. If I would build an array out of these two, I would result in a 3D-array which is not appropriate for Excel. (See attachment)

If I try to fit both parts of the program into one loop, after some time the buffer of the DAQ is overflowing because the sample rate is too high for the slow execution of the calculating part (for stimulation). The high sample rate is necessary to get an accurate value of the wrist angle though.

Everything besides (Measuring angle, stimulation, saving 2D data) this is working properly.

P.S. I`m glad to be alive in the 21. century, so that I can ask you guys for help!
Thank you so much!

Message 1 of 28
(3,618 Views)

## Transfering/ writing data from two while loops in Excel

Hello everyone,

First of all, I started to use Labview two months ago so I`m a total beginner. (Using  Labview 19, Windows 10 Pro, i5-6500 @ 3.2 GHz)

Now the challenge:

In general, I want to stimulate the muscles of the forearm to measure the resulting angle of the wrist-based on the stimulation intensity. So higher stimulation amplitude leads to a larger wrist angle.

Therefore, I use two while loops. One is calculating the stimulation intensity which should be increased every second (1 Hz). The second is about measuring the wrist angle of the wrist using a goniometer with a sample rate of 100 Hz.

While executing the program, I want to save the data into an Excel file to relate stimulation intensity/ voltage and resulting wrist angle. But when I pass the data out of the while loops to the Excel sheet, the resulting format is a 2D-array for each loop. If I would build an array out of these two, I would result in a 3D-array which is not appropriate for Excel. (See attachment)

If I try to fit both parts of the program into one loop, after some time the buffer of the DAQ is overflowing because the sample rate is too high for the slow execution of the calculating part (for stimulation). The high sample rate is necessary to get an accurate value of the wrist angle though.

Everything besides (Measuring angle, stimulation, saving 2D data) this is working properly.

P.S. I`m glad to be alive in the 21. century, so that I can ask you guys for help!
Thank you so much!

Message 2 of 28
(3,666 Views)

## Re: Transfering/ writing data from two while loops in Excel

Hi johnson,

@johnson64 wrote:

Therefore, I use two while loops. One is calculating the stimulation intensity which should be increased every second (1 Hz). The second is about measuring the wrist angle of the wrist using a goniometer with a sample rate of 100 Hz.

While executing the program, I want to save the data into an Excel file to relate stimulation intensity/ voltage and resulting wrist angle. But when I pass the data out of the while loops to the Excel sheet, the resulting format is a 2D-array for each loop. If I would build an array out of these two, I would result in a 3D-array which is not appropriate for Excel. (See attachment)

You are using way too much local and global variables.

And there is no "Excel"-related code in your images. All I see is the WriteDelimitedSpreadsheet function, which creates a formatted text file, which happens to also being readable by Excel.

Suggestion:

- Read 100 samples from the fast DAQmx task, and calculate your data. Put the resulting 100 (?) samples in a queue.

- Read 1 sample from slow task. Put the sample into a notifier.

- Read the queue in the file writing loop. Once you get data from the queue you also read the latest data from notifier: initialize an array of 100 elements with this. Build a 2D array from both arrays (from queue and notifier) and save that 2D array…

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 28
(3,635 Views)

## Re: Transfering/ writing data from two while loops in Excel

Thank u GerdW!

I will try my best to build your suggestion.

One question though:

What is the best method to make sure that the slow task is taking "exact" one second? I mean if the slow loop needs even just slightly more than 1 second, the corresponding angle isn`t included in the queue anymore, is it? Because, if the queue is filled up with the 100 values, it will just store them, right? What if the corresponding value would be the 105. value due to a small deviation caused by the slow task.

Right now I`m using Elapsed time. Is it better to just use a timer?

Just trying to figure out how this will/should work in the end.

Thank you!

Message 4 of 28
(3,622 Views)

## Re: Transfering/ writing data from two while loops in Excel

Hi johnson,

ElapsedTime is not a "timing" function (in the sense of waiting for some event), but just gives you the elapsed time.

When you want to "time" your loop you should either use Wait or WaitForNextMultiple…

When you want even better loop timing you should use the (hardware) timers on your DAQ device by setting a sample rate. That is very easy using the simple DAQmx functions, described here.

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 28
(3,612 Views)

## Re: Writing data from two while loops to an Excel sheet

Hi Freddi,

Welcome to the LabVIEW forums. As a brief introductory remark, you'll generally get better/more/faster help if you attach a full VI (or a zip of the project and all VIs, if necessary) rather than separate images showing disjointed parts of the block diagram. We could also then provide additional tips on other parts of your design (from the images I'd guess you might be able to reduce the number of Local Variables, for example).

That being said, I think you might be able to get what you want (or at least closer to it) by right clicking on the tunnels out of your While loops and choosing the "Concatenating" mode (under "Tunnel Mode")

This will effectively append data from each iteration into a big 1D array, allowing you to Build Array to get two sets.

Note that LabVIEW also won't allow "ragged" arrays - so if you have 100 elements in array one and 10000 elements (100x faster) in array two, the combination using Build Array will be a 10000x2 array (the extra values in the first row will be 0).

Message 6 of 28
(3,590 Views)

## Re: Writing data from two while loops to an Excel sheet

Hi freddi and johnson,

is there a reason to start two threads with the very same questions, images, even the same text of the messages using two different accounts?

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 28
(3,578 Views)

## Re: Writing data from two while loops to an Excel sheet

@GerdW wrote:

Hi freddi and johnson,

is there a reason to start two threads with the very same questions, images, even the same text of the messages using two different accounts?

Cmon, that's not true! Johnson specified some information about the computer (s)he's using! 😉

Message 8 of 28
(3,575 Views)

## Re: Writing data from two while loops to an Excel sheet

Hi cbutcher,

ok, I should have written "phrases" instead of "text"…

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 9 of 28
(3,572 Views)

## Re: Writing data from two while loops to an Excel sheet

haha the reason for this is my impatience. Bc the first post got somehow blocked by the system so I just posted it again and even added some important details. Sorry about that.

The additional local variables are just for error searching purposes, but thanks. When everything is working as desired, I will delete the unnecessary ones.

But once again for the advice! I will try my best to build it this way.

Next time when I struggle I will upload the part of the program if this is more helpful.

Message 10 of 28
(3,394 Views)