Filter löschen
Filter löschen

Need help FOR loop question 3

1 Ansicht (letzte 30 Tage)
Reynaldo Ponce
Reynaldo Ponce am 26 Feb. 2019
Kommentiert: Reynaldo Ponce am 3 Mär. 2019
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)]'

Akzeptierte Antwort

Naman Bhaia
Naman Bhaia am 1 Mär. 2019
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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by