write a program that doubles the elements that are positive and are divisible by 3 or 5, and raises to the power of 3 the elements that are negative, but greater than -5 in matlab

main.m
% create an array of numbers
array = [-6, 9, 12, 2, 0, -8, -4, 21];

% loop through the array
for i = 1:length(array)
    
    if array(i) > 0 && mod(array(i), 3) == 0 || mod(array(i), 5) == 0
        % if positive and divisible by 3 or 5, double the element
        array(i) = array(i) * 2;
        
    elseif array(i) < 0 && array(i) > -5
        % if negative and greater than -5, raise to the power of 3
        array(i) = array(i) ^ 3;
    
    end
    
end

% display the updated array
disp(array);
506 chars
21 lines

gistlibby LogSnag