필터 지우기
필터 지우기

Need help FOR loop question 3

조회 수: 1 (최근 30일)
Reynaldo Ponce
Reynaldo Ponce 2019년 2월 26일
댓글: Reynaldo Ponce 2019년 3월 3일
1.Declare and suppress the output of the following variables in the most succinct manner possible:
A=[1,2,3,4,5]
B=[2,5,8,11,14]
C=[20, 15, 10, 5, 0]
D =[-5, -4, -3, -2, -1]
E = [1, -7, 3, - 9, 5]
2.Declare and assign the following variables and print the output:
  • BIG: First column is A, second column is B, the third column is C, the fourth column is D, the fifth column is E.
  • small: First row is elements 1 through 3 of A, second row is elements 2 through 4 of C, third row is elements 3 through 5 of E.
3.Using a FOR loop, perform the following manipulations suppress the output (30 points).
  • new_A = A + loop counter
  • new_B= B – loop counter
  • new_C= C * loop counter
  • new_D= D / loop counter
  • new_E= E (Does not need to be done inside the FOR loop)
%so far for question 1 and 2 I have this but am having a hard time with questioin 3
%declaring variables
clc
A=[1:5];
B=[2:3:14];
C=[20:-5:0];
D=[-5:-1];
E=[1,-7,3,-9,5];
%declaring and assigning variables BIG1 and small1
BIG1=[A',B',C',D',E']
small1=[A(1:3);C(2:4);E(3:5)]'

채택된 답변

Naman Bhaia
Naman Bhaia 2019년 3월 1일
Hey Reynaldo,
Try the following code as an answer
for i=1:5
new_A(i) = A(i)+i;
new_B(i) = B(i)-i;
new_C(i) = C(i)*i;
new_D(i) = D(i)/i;
end
new_E = E;
Also for future questions, please upload whatever code you have tried to write so that people trying to answer your query have a starting point and should not feel like they're just completing your assignment for you.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by