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?

 採用された回答

David Hill
David Hill 2020 年 8 月 13 日

0 投票

yourVector.*(0:length(yourVector)-1);

3 件のコメント

Muzoun Alnaqbi
Muzoun Alnaqbi 2020 年 8 月 13 日
I am getting an error. is lenght here is number of elements in that vector?
David Hill
David Hill 2020 年 8 月 13 日
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);
Muzoun Alnaqbi
Muzoun Alnaqbi 2020 年 8 月 13 日
thank you.

サインインしてコメントする。

その他の回答 (1 件)

madhan ravi
madhan ravi 2020 年 8 月 13 日

0 投票

vector(:) .*(0:numel(vector(:)) - 1)

1 件のコメント

madhan ravi
madhan ravi 2020 年 8 月 13 日
Are you trying to finish your homework by making others do it? Start with MATLAB On-ramp.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File 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