my for loop stop after the first valid number has been found how do i fix this
I am new to Matlab, just learned the for loop, basically the loop run properly, but stop after the first valid number has found.
numbers=importdata(‘numbers.txt’);
result_1=[];
for i =1:numel(numbers);
num=numbers(i);
if mod(num, 10) == 6 && mod(num, 4) == 0
answer_1=[result_1,num];
end
end
fprintf(‘The numbers that ends in 6 and are divisible by 4: n’);
fprintf(‘%dn’,answer_1)I am new to Matlab, just learned the for loop, basically the loop run properly, but stop after the first valid number has found.
numbers=importdata(‘numbers.txt’);
result_1=[];
for i =1:numel(numbers);
num=numbers(i);
if mod(num, 10) == 6 && mod(num, 4) == 0
answer_1=[result_1,num];
end
end
fprintf(‘The numbers that ends in 6 and are divisible by 4: n’);
fprintf(‘%dn’,answer_1) I am new to Matlab, just learned the for loop, basically the loop run properly, but stop after the first valid number has found.
numbers=importdata(‘numbers.txt’);
result_1=[];
for i =1:numel(numbers);
num=numbers(i);
if mod(num, 10) == 6 && mod(num, 4) == 0
answer_1=[result_1,num];
end
end
fprintf(‘The numbers that ends in 6 and are divisible by 4: n’);
fprintf(‘%dn’,answer_1) help for loop not working properly MATLAB Answers — New Questions