The next Matab code, I need to keep the number of the last iteration:

A, B, arrays N numbers, increasing linearly.

for i 1:1:10

    if A(i) < B(i) && A(i+1) > B(i+1)

    number = i

    end

end

disp(i)

Unfortunately this code is not working.

I need to find and keep the number i, in which the relation A and B is changing.

any help is more than welcome

有帮助吗?

解决方案

Is this what you're trying to do?

A=rand(20,1);
B=rand(20,1);
for i=1:1:10

    if A(i) < B(i) && A(i+1) > B(i+1)
        number = i;
        break;  % Did you intend to stop when condition was satified?
    end

end
% Presumably you wanted to display the stored index 
% (although since we now break i and number will be the same)
disp(number)   

BTW, Best to post code that can be run in your question. Makes it easier for people answering to see the problem.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top