How to fill matrix in for loop?

1 回表示 (過去 30 日間)
I G
I G 2019 年 1 月 11 日
編集済み: Stephen23 2019 年 1 月 11 日
I need to fill matrix r, where r=r(z), and ri is constant. But with this code I onlu get the first row where r=-0.7:0.7.
z=-1:0.001:0;
ri=0.7;
R=ri-z*(ri-1);
for z=-1:0.001:0;
r=(linspace(-(ri-z*(ri-1)),ri-z*(ri-1),1001))
end
My full matrix need to be in this shape, or transpose of this:
-0.7...... 0.7
0.8 ... 0.8
. .
. .
. .
0 .9 ... 0.9
. .
. .
. .
1 ... 1

採用された回答

Stephen23
Stephen23 2019 年 1 月 11 日
編集済み: Stephen23 2019 年 1 月 11 日
>> (0.7:0.05:1).'*(0:0.2:1)
ans =
0.00000 0.14000 0.28000 0.42000 0.56000 0.70000
0.00000 0.15000 0.30000 0.45000 0.60000 0.75000
0.00000 0.16000 0.32000 0.48000 0.64000 0.80000
0.00000 0.17000 0.34000 0.51000 0.68000 0.85000
0.00000 0.18000 0.36000 0.54000 0.72000 0.90000
0.00000 0.19000 0.38000 0.57000 0.76000 0.95000
0.00000 0.20000 0.40000 0.60000 0.80000 1.00000
Adjust the step sizes to suit your requirements.

その他の回答 (1 件)

KSSV
KSSV 2019 年 1 月 11 日
編集済み: KSSV 2019 年 1 月 11 日
z=-1:0.001:0;
ri=0.7;
R=ri-z*(ri-1);
[R,Z] = meshgrid(z,R) ;
r = R-Z.*(R-1) ;
  1 件のコメント
I G
I G 2019 年 1 月 11 日
編集済み: I G 2019 年 1 月 11 日
This does not work for me because I got matrix with values from 0.7 to 1 in this shape:
1 1 .... 1
.
.
1 0.997 .... 0.7
and it need to be with these values:
-0.7...... 0.7
-0.8 ... 0.8
. .
. .
. .
-0.9 ... 0.9
. .
. .
. .
-1 ... 1
or with values:
0 ...... 0.7
0 ... 0.8
. .
. .
. .
0 ... 0.9
. .
. .
. .
0 ... 1

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by