![]() |
在MATLAB中如何在特定点之后获取值并丢弃之前的值?
我有一个数组,比方说
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 我该怎么做? [B]回答:[/B] 这是一种方法: >> 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的多个条目,您可以更改[URL="http://www.mathworks.com/help/techdoc/ref/find.html"]find[/URL]的使用方式。例如,如果您要从最后一个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从未出现在数组中,或者至少出现了两次(对于最后一个示例)。 [url=https://stackoverflow.com/questions/4004369]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 23:15。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.