inserting into certain locations in array
1 回表示 (過去 30 日間)
古いコメントを表示
A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
B = [ 10 20 30]
C= 3 % is the position where I want to insert B in A
I = 2 % is the number of times or multiple
output must be:
F = [ 1 2 3 10 20 30 4 5 6 10 20 30 7 8 9 10 11 12 13 14 15]
if C= 2 and I = 4
then, F = [ 1 2 10 20 30 3 4 10 20 30 5 6 10 20 30 7 8 10 20 30 9 10 11 12 13 14 15]
0 件のコメント
採用された回答
Bob Thompson
2019 年 2 月 12 日
F = A;
for i = 1:I
F = [F(1:C*i+length(B)*(i-1)),B,F(C*i+length(B)*(i-1)+1:end)];
end
0 件のコメント
その他の回答 (1 件)
liju Abraham
2019 年 2 月 12 日
3 件のコメント
Bob Thompson
2019 年 2 月 12 日
Yes, if you are plotting against another array you will need to account for the extra entries in your F array.
If you are having an error feel free to post it here.
FYI: I don't know if a mod will see this, but they prefer to have 'answers' be actual answers, not comment responses. They may ask you to move your answer to a comment under my answer, or will move it for you.
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!