Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

DFMarq

Member

07-08-2020 06:37 AM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hello,

I have writed a VI to control a lock-in amplifier and a power supply.

I have a big while loop which in each iteration generates 4 arrays that I put in 2 clusters that go to a XY graph (the lock in measures for a negative current and positive current, so I have a ramp that for example goes from -2 to 2 A and then from 2 to -2 A).

So, at the end I have something like this ploted in a single XY graph inside a while loop:

-2 0.056 2 0.046

-1 0.052 1 0.048

0 0.050 0 0.050

1 0.048 -1 0.052

2 0.046 -2 0.056

Now I want to average this XY graphs that are being generated in every loop interaction.

I tried to index the 4 arrays outside the loop, average each one and put them together as I did inside the loop, but it does not generate any plot.

I also tried to index outside the loop the final appended array (the XY graph) but I don't find any way to average it, as the add array elements function does not work with 1D array of 2 clusters.

Is there any easy way to average the XY graphs for the number of loops I set on the while loop? At the end I would like to have for example the 3 XY graphs and another graph with the average of the 3 graphs.

Thank you in advance,

GerdW

Knight of NI

07-08-2020 06:45 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

07-08-2020 07:00 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Thanks for the reply,

As I am a novice programmer I did not use sub-Vi so I have a giant while structure with everything mixed so I think is easier for you if I explain it. At the end I have 4 1D arrays that I want to average outside the while loop N-times.

However, I will try to cut the problem structure so you can check it.

wiebe@CARYA

Proven Zealot

07-08-2020 08:24 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@DFMarq wrote:

Thanks for the reply,

As I am a novice programmer I did not use sub-Vi so I have a giant while structure with everything mixed so I think is easier for you if I explain it.

A giant while loop is hard to handle, even for advanced programmers! That is why we avoid it...

Complex code is, well, complex. Break things down to simple blocks, to make things simple. Especially if you're a beginner. Break the rules when you're advanced, so you at least know how to deal with the consequences.

Just a friendly advice, feel free to ignore.

LabVIEW Programming ((make LV more popular, read this)

johntrich1971

Active Participant

07-08-2020 09:24 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@DFMarq wrote:

Thanks for the reply,

As I am a novice programmer I did not use sub-Vi so I have a giant while structure with everything mixed so I think is easier for you if I explain it. At the end I have 4 1D arrays that I want to average outside the while loop N-times.

However, I will try to cut the problem structure so you can check it.

I agree with wiebe@CARYA, learn to use subvis. It will make your life a lot easier.

Also, a picture is worth a thousand words, and a vi (even a bad one) is worth 10,000 words.

07-08-2020 04:24 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

So I made a VI that summs up what I have in my original code. Do not pay attention to what it is inside the loops, as it does not have any sense at all. The important thing is the four 1D array strings that go to the XY plot. The arrays have allways the same length in the original VI.

What I am trying to do is to average the XY graph (or the 4 1D array strings) the N number of times the while loop runs. For example if I perform 3 measurements now I have 3 plots on the XY chart but I would like to have another XY graph with the average of the 3 measurements when it goes outside the final while loop.

I tried to use the resulting cluster string and also to put the 4 1D arrays indexed outside as a matrix but I can not average the arrays no matter what I try to do.

GerdW

Knight of NI

07-09-2020 02:47 AM - edited 07-09-2020 02:48 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hi DFMarq,

@DFMarq wrote:

The important thing is the four 1D array strings that go to the XY plot. The arrays have allways the same length in the original VI.

What I am trying to do is to average the XY graph (or the 4 1D array strings) the N number of times the while loop runs. For example if I perform 3 measurements now I have 3 plots on the XY chart but I would like to have another XY graph with the average of the 3 measurements when it goes outside the final while loop.

I tried to use the resulting cluster string and also to put the 4 1D arrays indexed outside as a matrix but I can not average the arrays no matter what I try to do.

First of all this VI is a mess. Why do you use WHILE loops when you want to use FOR loops for a fixed amount of iterations? Your VI could look like this:

(I hope I did all changes correctly. Please verify.)

You are talking about "measurements" in your question: there is no control labelled "measurements". Instead there is "numeric2" and "numeric3" setting the amount of loop iterations: which one are you talking about? You are talking about "the loop" but there are several loops stacked inside of each other: which one are you talking about?

Why did you use mostly DBL when all the loops expect I32 values for iteration counts?

Hint:

When you want to calculate an average of the data created in the "middle" FOR loop then you should wire that data using autoindexing tunnels outside of the outer loop. You will get a 2D array for each 1D array inside the loop and can average the data row-wise…

(Ofcourse you can do the summing inside the outer loop and only need to divide by the loop iteration count after that loop. Now you just need a shift register!)

07-09-2020 03:33 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

First of all, thanks for your answer and sorry for the mess.

I used while loops because in the big code all the whiles except the outer one (numeric 3) have a variable number of iteractions.

The loop I want to use to average my 4 1D arrays is the outer one, the numeric 3 in this case, so if for example I set numeric 3= 4 loops I would like to average the four 1D arrays (or the cluster that goes to the xy graph inside the while) four times.

I tried several things but at the end I did not manage to average these arrays by rows, it allways result in a xy plot with a straight line.

GerdW

Knight of NI

07-09-2020 03:47 AM - edited 07-09-2020 03:48 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hi DFMarq,

@DFMarq wrote:

I tried several things but at the end I did not manage to average these arrays by rows, it allways result in a xy plot with a straight line.

Why don't you show what you have tried so we could provide help to improve your code?

Suggestion:

The inner loop creates a plot of 10 samples.

Using the shift register the plots of each iteration of the outer loop are averaged…