MATLAB problem: So far I programmed this: However, this only displays the last c
ID: 3575942 • Letter: M
Question
MATLAB problem:
So far I programmed this:
However, this only displays the last calulated element of the array. I need to "build" a new array and display it when the function is executed. Can anyone help?
4. Create a function called changearray(A) that would add 20 to all non-positive elements of an array A and take the natural logarithm of all positive elements of A? A randn (4,5) 5 1.5176 8.5594 6.7730 7.1835 14.5400 3.0016 -0.9706 5.3608 9.8045 4.1261. 2.4498 -10.6918 4.8048 -0.9885 6.8949 3.6968 4.1979 0.6202 6.0392 5.2909 changearray (A) 0.4171 2.1470 1.9129 1.9718 2.6769 16.9984 19.0294 14.6392 10.1955 1.4173 0.8960 9.3082 1.5696 19.0115 1.9308 1.3075 15.8021 0.4776 13.9608 14.7091Explanation / Answer
function z = changearray(A)
s = size(A);
nr = s(1);
nc = s(2);
z = zeros(nr,nc);
for i = 1:nr
for j = 1:nc
z(i)(j) = log(A(i)(j));
if ( A(i)(j) < 0 )
z(i)(j) = A(i)(j)+20;
end
end
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.