The For Loop and Waveform Graph
Bounded Iteration in Graphical Programs
Bounded iteration in graphical programs lets you repeat a calculation a specified number of times and display the resulting samples together. In LabVIEW, a For Loop provides the repetition, an indexing output tunnel collects the results, and a waveform graph displays them on a uniformly spaced horizontal axis. This pattern is useful when you generate a finite simulated signal or process a known collection of measurements.
Set the repetition bound
Bounded iteration is repetition with an upper limit on the number of executions. For a basic For Loop, wire a nonnegative integer to the count terminal N. Assume here that the loop has no early-stop condition. Without indexing input arrays, the loop executes N times.
The iteration terminal i uses zero-based numbering:
Consequently, the last iteration number is one less than the number of executions. If N=0, the loop body does not execute, so there is no last iteration.
An indexing input tunnel supplies one array element per iteration. When several indexing arrays enter the loop, their lengths also limit the count. With N wired and indexing input lengths L1,L2,…, the effective count is
If N is unwired, indexing input arrays can determine the count from their shortest length. An array passed through a non-indexing input tunnel does not impose this element-by-element limit.
Collect one result per iteration
Auto-indexing is a tunnel behavior that either selects successive input elements or collects successive output values. To build a signal, compute one scalar value yi inside the loop and enable indexing on its output tunnel. Ordinary output indexing collects every iteration's scalar into a one-dimensional array in iteration order.
Output tunnel setting | Result after a nonempty loop | Suitable for retaining every scalar sample? |
|---|---|---|
Indexing enabled | Array containing one value per iteration | Yes |
Indexing disabled | Scalar from the final iteration | No |
The tunnel setting determines what crosses the loop boundary. Changing a graph's appearance cannot recover samples that a non-indexing tunnel did not retain.
Give the samples a meaningful horizontal axis
A waveform graph represents samples at equal horizontal intervals. A numeric array wired directly to a graph with default horizontal scaling is plotted at 0,1,2,…. Those coordinates are sample indices; naming the axis Time does not supply a sampling interval.
For numeric time coordinates, bundle an initial horizontal value x0, a spacing Δx, and the array Y. When the horizontal quantity is time, use x0=t0 and Δx=Δt. Sample i then has time
For M samples, where M≥1, the final time and the first-to-last span are
For example, five samples separated by 0.030 s span 4(0.030)=0.120 s. There are four intervals between five points.
Place the graph outside the loop and supply the collected array after completion. Check the output length, first sample, and last sample against your intended time range.
What to remember
- N counts executions; i starts at zero.
- Indexing inputs can reduce the effective count.
- An indexing output retains every scalar result.
- M uniformly spaced samples span M−1 intervals.
Example: Generate a finite displacement signal
You are preparing a simulated motion signal to test a display before connecting any hardware. The displacement model is
Generate samples from t=0.000 s through t=0.400 s, including both endpoints, with spacing Δt=0.080 s. Use a LabVIEW For Loop with no indexing input arrays and no early stopping, then display the complete result on a waveform graph outside the loop.
Report times and displacements to three decimal places.
a) Determine the required count N and the iteration numbers used.
Divide the requested time span by the spacing to count intervals. Since both endpoints are included, add one to obtain the number of sample points.
Wire 6 to the count terminal. The six iteration numbers are i=0,1,2,3,4,5. The last iteration number is 5, which agrees with the ________ intervals between the endpoints.
b) Calculate the time and displacement at every iteration, and state how to retain the full output array.
Inside the loop, convert the dimensionless iteration number into a time, then evaluate the displacement model. Each multiplication of velocity by time gives a displacement in metres.
Substitute each iteration number into these expressions:
- At i=0, t0=0(0.080 s)=0.000 s and y0=0.015 m+(0.250 m/s)(0.000 s)=0.015 m.
- At i=1, t1=1(0.080 s)=0.080 s and y1=0.015 m+(0.250 m/s)(0.080 s)=0.035 m.
- At i=2, t2=2(0.080 s)=0.160 s and y2=0.015 m+(0.250 m/s)(0.160 s)=0.055 m.
- At i=3, t3=3(0.080 s)=0.240 s and y3=0.015 m+(0.250 m/s)(0.240 s)=0.075 m.
- At i=4, t4=4(0.080 s)=0.320 s and y4=0.015 m+(0.250 m/s)(0.320 s)=0.095 m.
- At i=5, t5=5(0.080 s)=0.400 s and y5=0.015 m+(0.250 m/s)(0.400 s)=0.115 m.
Use numeric constants expressed in seconds, metres, and metres per second consistently. Wire the scalar displacement calculation to an output tunnel with ordinary indexing enabled. It collects the six values in iteration order:
The displacement increment is constant:
Every adjacent pair in the array differs by this amount, providing a useful arithmetic check.
c) Specify the graph input and verify the final plotted point.
Outside the loop, use Bundle to form the numeric cluster (x0,Δx,Y). Set x0=0.000 s and Δx=0.080 s, and supply the collected displacement array as Y. Wire that cluster to the waveform graph and label its axes Time (s) and Displacement (m).
The final array index is N−1=5, so its graph coordinate is
Its displacement is
The final plotted point is therefore (0.400 s,0.115 m). Supplying only the array with default graph scaling would instead place its final value at horizontal coordinate ________. The timing cluster assigns the intended physical coordinates; it does not control how long the simulation takes to execute.
On two separate runs of a LabVIEW program, a For Loop produces a complete voltage array. After each loop finishes, its array is written directly to the same single-plot Waveform Graph.
The first run writes [1,2,3,4] V. The second run writes [−2,0,2] V. No other code stores or combines the arrays.
After the second write, the graph displays points, and the first point has a y value of V.
A LabVIEW For Loop generates 81 voltage samples, one per iteration, and retains all of them through an indexing output tunnel. The loop has no indexing inputs or early stopping. A waveform graph receives the cluster (x0,Δx,Y) with x0=1.200 s and Δx=0.025 s. What is the time coordinate of the final sample? Answer in seconds, to three decimal places.