可以使用Matlab函数find来查找数组中非零元素的位置,然后取第一个非零元素的位置即为数组的非零起始位置。具体步骤如下:

  1. 定义一个数组,例如A = [0 0 0 1 2 3 0 0]

  2. 使用find函数查找非零元素的位置,例如p = find(A ~= 0)

  3. 取第一个非零元素的位置,例如start_pos = p(1)

start_pos即为数组A的非零起始位置。

完整代码如下:

A = [0 0 0 1 2 3 0 0];
p = find(A ~= 0);
start_pos = p(1);
disp(start_pos);

原文地址: https://www.cveoy.top/t/topic/bPv5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录