Given: x = [13, 5, 7, 9, 1, 4, 7, 10, 13] Use one \'for loop\' to create the mat
ID: 3801738 • Letter: G
Question
Given: x = [13, 5, 7, 9, 1, 4, 7, 10, 13] Use one 'for loop' to create the matrix y of dimension 5X2, using the index to program the address and the value of each element of y; and y = x' Given, x = [2, 3, 4, 5, 3, 4, 5, 6] Use two 'for loops' to create the matrix of dimension 4X2 Use a while statement to determine when the sum of the numbers in the series 1, 2, 3, 4 is greater than 55. Given A = [2, 9, 4, 5, 9, 7, 8, 6] use a 'for loop' and 'if' statement to set all the values below 4 to 0 in A.Explanation / Answer
1. Here we can see that difference between each element of first row and second row of matrix x is getting incremented. So, we can implement our code as follows:
x=[1,3,5,7,9];
y=zeros(5,2);
y(:,1)=x;
for i=0:4
y(i+1,2)=x(i+1)+i;
end
y
output:
2.
A=[2,3,4,5;3,4,5,6];
B=zeros(4,2);
[row col] = size(A);
for m=1:row
for n=1:col
B(n,m)=A(m,n);
end
end
B
output:
3.
i=1;
sum=0;
while(sum<=55)
sum=sum+i;
i++;
end
i
This indicates that sum of numbers is greater than 55 after the result i.e. i in the code.
output:
i = 12
4.
A = [2,9,4,5,9,7,8,6];
row = size(A);
for i=1:row
if(A(i)<4)
A(i)=0;
end
end
A
The result would be : A = [0,9,4,5,9,7,8,6]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.