How we can expand matrix A to B? each element of matrix A is equal to sum of each B columns. (step of 3)
A=
[1 5 8 12 7 5 2 1]
to B=
1 3 3 3 3 3 2 1
0 2 3 3 3 2 0 0
0 0 2 3 1 0 0 0
0 0 0 3 0 0 0 0
0 0 0 0 0 0 0 0

4 件のコメント

jgg
jgg 2016 年 1 月 22 日
Aren't there a very large number of ways to do this? Is there some specific form you want?
Star Strider
Star Strider 2016 年 1 月 23 日
It seems that it’s constrained to use only {1, 2, 3}. That may be what ‘step of 3 refers to.
Mori
Mori 2016 年 1 月 23 日
I will use this code for a large Matrix with large numbers. 3 is the gris size, in real data will be 300. I will post the results. Thanks
Mori
Mori 2016 年 1 月 23 日
Yea, works perfectly. Thnaks

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

 採用された回答

jgg
jgg 2016 年 1 月 23 日
編集済み: jgg 2016 年 1 月 23 日

0 投票

This should work
A = [1 5 8 12 7 5 2 1];
floors = floor(A./3);
C = cumsum(3.*ones(max(floors)+1,length(A)),1)
A_p = repmat(A,max(floors)+1,1);
res = 3.*(C <= A_p);
remainder = A - sum(res);
r = cellfun(@(row) find(row == 0, 1, 'first'), num2cell(res,1));
ind = sub2ind(size(res),r,[1:length(A)]);
res(ind) = remainder;

1 件のコメント

Mori
Mori 2016 年 1 月 23 日
thanks, it works

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2016 年 1 月 22 日

コメント済み:

2016 年 1 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by