adding an array with steps untli the last row

Hello,
How is it possible to create an Array that starts at 0.02 and Ends at the last row of a second Array like 5x1? For example:
a=round(5,1)
a=
5
1
2
4
5
Now I want a second array with the same ammount of rows but starts with 0.02 and adds 0.02 every row like 0.02 0.04 0.06 and so on until the last row of the other array...
If I choose size the Array Counts until the last number of the other Array is reached... please help me!

2 件のコメント

Guillaume
Guillaume 2017 年 3 月 17 日
Presumably,
a=round(5, 1)
is meant to be
a = randi(5, 5, 1);
Felifa
Felifa 2017 年 3 月 17 日
oh I'm sorry, I of course I ment a=rand(5,1)

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

回答 (3 件)

KSSV
KSSV 2017 年 3 月 17 日

0 投票

Say you want 5 values...
N = 5 ;
i = 0:N-1 ;
iwant = 0.02+i*0.02

2 件のコメント

Guillaume
Guillaume 2017 年 3 月 17 日
i = 1:N;
iwant = 0.02*i;
would be simpler.
KSSV
KSSV 2017 年 3 月 17 日
Yes..yes you are right..@Guillaume

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

Guillaume
Guillaume 2017 年 3 月 17 日
編集済み: Guillaume 2017 年 3 月 17 日

0 投票

newarray = 0.02 * reshape(1:numel(a), size(a))
would work and produce an array/matrix the same shape of A, regardless of that shape.

3 件のコメント

Felifa
Felifa 2017 年 3 月 17 日
編集済み: Felifa 2017 年 3 月 17 日
Oh very nice, that works perfectly :D Thank you so much!!!
tarek rahmani
tarek rahmani 2017 年 3 月 17 日
correction: ('numel' not 'nume')
newarray = 0.02 * reshape(1:numel(a), size(a))
Guillaume
Guillaume 2017 年 3 月 17 日
Yes, thanks for noticing.

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

tarek rahmani
tarek rahmani 2017 年 3 月 17 日

0 投票

a=[min:step:max]
for ex:
>> a=[1:0.2:2]
a =
1.0000 1.2000 1.4000 1.6000 1.8000 2.0000

1 件のコメント

Felifa
Felifa 2017 年 3 月 17 日
The problem here is that I am importing data from Excel from meassurements, so I don't know the size of the Array. Therefor the Version of Guillaume is the best for my problem. But thank you though!

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

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

タグ

質問済み:

2017 年 3 月 17 日

編集済み:

2017 年 3 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by