Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我有一个数组,比方说
A = 1 2 3 4 5 6 7 8 9 2 3 4 3 4 5 1 6 8 我从第3列中得出一个观点,假设p = 9。 现在,我想要一个新数组,该数组为我提供9之后的所有值,并丢弃9之间的所有值。例如: ans = 7 8 9 2 3 4 3 4 5 1 6 8 我该怎么做? 回答: 这是一种方法: >> p = 9; >> startrow = find(A(:, 3) == p, 1); % first row where 3rd column entry is p >> A1 = A(startrow:end, :) A1 = 7 8 9 2 3 4 3 4 5 1 6 8 编辑: 在最后一列中有p的多个条目,您可以更改find的使用方式。例如,如果您要从最后一个p而不是第一个p开始,则可以运行 >> startrow = find(A(:, 3) == p, 1, 'last'); % last row where 3rd column entry is p 如果您想从第二开始,则需要做更多的工作: >> startrows = find(A(:, 3) == p, 2); % first two rows where 3rd column entry is p >> startrow = startrows(end); % Just the second row where 3rd column entry is p 另外,您可能需要进行错误检查,以检查是否有可能p从未出现在数组中,或者至少出现了两次(对于最后一个示例)。 更多&回答... |
![]() |
![]() |