how to modify all elements in a row vector
14 views (last 30 days)
Show older comments
Muzoun Alnaqbi
on 13 Aug 2020
Commented: Muzoun Alnaqbi
on 13 Aug 2020
Hello I wanted to ask if I have a row vector and I want to medofy each element of the vector in such way that element 1 is equal to (element 1 *0), and element2= (element2*1) and element3= (element3*2) and so on. is possible to implement this is matlab? do I need a loop?
0 Comments
Accepted Answer
David Hill
on 13 Aug 2020
yourVector.*(0:length(yourVector)-1);
3 Comments
David Hill
on 13 Aug 2020
You should not be getting any errors. If you cut and paste this into your command prompt, you are getting an error?
yourVector=1:10;
newVector=yourVector.*(0:length(yourVector)-1);
More Answers (1)
madhan ravi
on 13 Aug 2020
vector(:) .*(0:numel(vector(:)) - 1)
1 Comment
madhan ravi
on 13 Aug 2020
Are you trying to finish your homework by making others do it? Start with MATLAB On-ramp.
See Also
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!