consider the following MATLAB code. What elements of x will be summed up. x= [3
ID: 3771349 • Letter: C
Question
consider the following MATLAB code. What elements of x will be summed up.
x= [3 4 5 6 7; 1 2 4 6 8; 5 7 9 1 3; 8 7 6 5 4; 9 8 7 6 5]
total=0 for n=2:2:4
for k = 1:1:3
total = total + x(k,n)
end
end
second question: how would i be able to test this myself? Would I use the command window of MATLAB or the editor?
Explanation / Answer
1. value of x which will be summed : 4, 2, 7, 6 , 6 , 1
2. you have to print the value of x(k,n) which will be added with total. I have bold that code in code, check it
that will print value of x every time before added with total.
x= [3 4 5 6 7; 1 2 4 6 8; 5 7 9 1 3; 8 7 6 5 4; 9 8 7 6 5];
total=0;
for n=2:2:4
for k=1:1:3
x(k,n)
total=total + x(k,n);
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.