HELP on computing an array from the previously given array with two adjustments.

1 view (last 30 days)
hmm so i have an array which is A = [3,5,-4;-8,-1,33;-17,6,-9], and i have to compute an array B by computing the natural logarithm of elements of A whose value is no less than 1, but adding 20 to all the other elements. I also have to use a "for" loop with conditional statements to make B. So far i have,
A=[ 3, 5, -4; -8,-1, 33; -17, 6, -9];
B=zeros(size(A));
for i=1:size(A,1)
for j=1:size(A,2)
if(A(i,j)>=1)
B(i,j)=A(i,j)+20
else
B(i,j)=log(A(i.j))
end
end
end
this does not work apparantly, can you guys help me with this! its bugging me really bad!

Accepted Answer

Walter Roberson
Walter Roberson on 8 Nov 2013
Edited: Walter Roberson on 8 Nov 2013
Add 20 to the other elements, not the ones that are "no less than 1"
And log(A(i.j)) should be log(A(i,j))
  2 Comments
Jay
Jay on 8 Nov 2013
i tried switching it around, only to get an error saying " A = | Error: Expression or statement is incomplete or incorrect."

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!