write a for loop 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 in matlab

main.m
% Create an example array
arr = [-6, 2, 8, -2, 6, 11, -4, 7, -8, 5];

% Loop through all elements of the array
for i = 1:length(arr)
  
  % Check if the element is positive and divisible by 3 or 5
  if arr(i) > 0 && mod(arr(i),3)==0 || mod(arr(i),5)==0
    arr(i) = arr(i)*2; % Double the element
    
  % Check if the element is negative and greater than -5
  elseif arr(i) < 0 && arr(i) > -5 
    arr(i) = arr(i)^3; % Raise to the power of 3
    
  end
  
end

% Display the modified array
disp(arr)
502 chars
21 lines

gistlibby LogSnag