display the elements of a matrix a with elements form 1 to 100 that are divisible by 7 in matlab using for loop and if function in matlab

main.m
matrix = 1:100;
for column = 1:10
    for row = 1:10
        index = row + 10 * (column - 1);
        if mod(matrix(index), 7) == 0
            disp(matrix(index));
        end
    end
end
189 chars
10 lines

In this code, we first create a matrix with elements from 1 to 100 using the syntax matrix = 1:100. We then use a nested for loop to iterate over each element in the matrix. Within each iteration, we calculate the index of the current element using the formula index = row + 10 * (column - 1). We use mod function to check if the element is divisible by 7. If the mod function returns a result of 0, indicating that the element is divisible by 7, disp function is used to display the element.

gistlibby LogSnag