I'm newish to MATLAB and want to automate populating a matrix A rather than manually create...

1 次查看(过去 30 天)
My columns represent years, and the rows the demand profile TM (versus a peak demand) for products each year. I could launch 1 2 or 3 products per year.
The demand profile starts slow, builds to a peak and tails to zero 20 years after launch
TM = [0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4 0.2 0.1 0.0]
The typical demand profile looks like this, and is the same for each product TM(1:N):
TM1 = [0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4 0.2 0.1 0.0....]
If products launched/yr = 1 then the second product curve would look like
TM2 = [0 0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4 0.2 0.1 0.0....];
If products lanched/yr = 2 then the second product curve would look like TM1, and the third like TM2
TM2 = [0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4 0.2 0.1 0.0];
and
TM3 = [0 0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4 0.2 0.1 0.0....];
So I might end up with something like this for one product a year and four products...
A=
[0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4 0.2 0.1 0.0;
0.0 0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4 0.2 0.1;
0.0 0.0 0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4 0.2;
0.0 0.0 0.0 0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4];
Any pointers appreciated, Thank you.

采纳的回答

Stephen23
Stephen23 2021-12-23
编辑:Stephen23 2021-12-23
TM = [0.1,0.1,0.1,0.1,0.1,0.2,0.3,0.4,0.6,0.8,1.0,1.0,1.0,1.0,1.0,0.8,0.6,0.4,0.2,0.1,0.0];
N = 4;
M = toeplitz([TM(1),zeros(1,N-1)],TM)
M = 4×21
0.1000 0.1000 0.1000 0.1000 0.1000 0.2000 0.3000 0.4000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.4000 0.2000 0.1000 0 0 0.1000 0.1000 0.1000 0.1000 0.1000 0.2000 0.3000 0.4000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.4000 0.2000 0.1000 0 0 0.1000 0.1000 0.1000 0.1000 0.1000 0.2000 0.3000 0.4000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.4000 0.2000 0 0 0 0.1000 0.1000 0.1000 0.1000 0.1000 0.2000 0.3000 0.4000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8000 0.6000 0.4000
plot(M.')
Compared to your requested output:
A = [0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4 0.2 0.1 0.0;
0.0 0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4 0.2 0.1;
0.0 0.0 0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4 0.2;
0.0 0.0 0.0 0.1 0.1 0.1 0.1 0.1 0.2 0.3 0.4 0.6 0.8 1.0 1.0 1.0 1.0 1.0 0.8 0.6 0.4];
plot(A.')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by