looper

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 5.1, Creation date: 2021-03-21, Last change: 2025-09-15

converts a sequence into a one-line sequence for a For loop

Description

At some point in Matlab, a line sequence seems to have been forced in for loops. In any case, multiple sequences of the form (nx1) versus (1xn) lead to annoying debugging. This function always converts any logical sequence or list of multiple lines to a single-line sequence

See Also:

Example Illustration

 missing image of looper(ind)

Syntax

ind=looper(ind)

Input Parameter

ind: index list for a for-Loop

Output Parameter

ind: corrent single line index list for a for-Loop

Examples


looper(true(3,3))
looper(true(1,10))
looper(true(10,1))
looper([1 3 5 4])
looper([1 3 5 4]')




Copyright 2021-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This algorithm is designed to convert a sequence into a one-line sequence suitable for use in a for-loop in MATLAB. It addresses the issue of MATLAB's handling of line sequences in for-loops, ensuring that any logical sequence or list of multiple lines is converted to a single-line sequence.

Input Parameters

Output Results

Algorithm Steps

  1. Check if the input ind is a logical array using islogical(ind).
  2. If ind is logical, convert it to a list of indices where the logical array is true using find(ind).
  3. Reshape the ind array into a single row using reshape(ind,1,[]). This ensures that the output is a one-line sequence.

Example Usage

Algorithm explaination created using ChatGPT on 2025-08-18 23:33. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21