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
- ind: This is the index list intended for use in a for-loop. It can be a logical array or a numeric array.
Output Results
- ind: The output is a corrected single-line index list suitable for a for-loop.
Algorithm Steps
- Check if the input
ind
is a logical array using islogical(ind)
.
- If
ind
is logical, convert it to a list of indices where the logical array is true using find(ind)
.
- Reshape the
ind
array into a single row using reshape(ind,1,[])
. This ensures that the output is a one-line sequence.
Example Usage
looper(true(3,3))
- Converts a 3x3 logical matrix to a single-line index list.
looper(true(1,10))
- Converts a 1x10 logical matrix to a single-line index list.
looper(true(10,1))
- Converts a 10x1 logical matrix to a single-line index list.
looper([1 3 5 4])
- Converts a numeric array to a single-line index list.
looper([1 3 5 4]')
- Converts a column vector to a single-line index list.
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