array_yourlogin

array_yourlogin - % % OUTPUT ARGUMENTS % new_array = the...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function[new_array]=array_yourlogin(A,user_val) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Programmer(s) and Purdue Email Address(es): % 1. @purdue.edu % % Section #:ALL % % Assignment #: Homework 6 problem 3 - Modifying an Array % % Academic Integrity Statement: % % I/We have not used source code obtained from % any other unauthorized source, either modified % or unmodified. Neither have I/we provided access % to my/our code to another. The project I/we am/are % submitting is my/our own original work. % % This function modifies the elements in an array based upon the following rules: % i. Double the value of the element if it is positive and divisible by a user specified value. % ii. Square the value of the element if it is negative. % iii. Use the original value for the elements that are not modified in steps i. or ii. % % INPUT ARGUMENTS % A - the original array % user_val - the user specified value
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % % OUTPUT ARGUMENTS % new_array = the modified array % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ---- Input Section ----[n,m] = size(A); new_array = zeros(n,m); % initialize new, modified array n % ---- Calculation Section ----for c = 1:m % loop through columns for r = 1:n % loop through rows if A(r,c) >=0 && rem(A(r,c),user_val) == 0 % checks if positive and divisible by user_val new_array(r,c) = A(r,c)*2; elseif A(r,c) < 0 % checks if negative new_array(r,c) = A(r,c)^2; else % fills in unchanged values new_array(r,c) = A(r,c); end end end e % ---- RESULTS ----% T = [5, 17, -3, 8, 0, -7, 12] % array_mod(T,4)= % 5 17 9 16 0 49 24 % % T = [1 5 3; -2 6 -7; -4 12 24] % array_mod(T,2) = % 1 5 3 % 4 12 49 % 16 24 48 % % T = [23 17 -34 66; -4 33 -23 0; 12 7 11 22; -2 0 0 7] % array_mod(T,11) = % 23 17 1156 132 % 16 66 529 % 12 7 22 44 % 4 0 0 7 %...
View Full Document

Page1 / 2

array_yourlogin - % % OUTPUT ARGUMENTS % new_array = the...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online