how to fit an array in matrix?

5 ビュー (過去 30 日間)
Abdulaziz Abutunis
Abdulaziz Abutunis 2015 年 10 月 8 日
回答済み: Image Analyst 2015 年 10 月 8 日
Hi All,
is there any function or command to fit (insert) an array in a 2D matrix by shifting the later arrays one step down so not to overwrite that array

採用された回答

Image Analyst
Image Analyst 2015 年 10 月 8 日
If the number of columns are the same, you can insert array2 into array 1 starting at row k like this:
outputArray = [array1(1:k-1,:); array2; array1(k:end,:)];
If the number of rows are the same, you can insert array2 into array 1 starting at column k like this:
outputArray = [array1(:, 1:k-1), array2, array1(:, k:end)];
If the number of rows and columns are different, then you'd basically have to paste the smaller on onto the larger one, overwriting values, or else insert a slab of zeros and then overwrite the zeros.

その他の回答 (1 件)

James Tursa
James Tursa 2015 年 10 月 8 日
What are the sizes involved? E.g., are you trying to insert a row at the front? E.g., is this what you want (assumes same number of columns for new_row and my_matrix):
new_row = whatever
my_matrix = whatever
my_matrix = [new_row;my_matrix]; % <-- insert new row at front
  1 件のコメント
Abdulaziz Abutunis
Abdulaziz Abutunis 2015 年 10 月 8 日
Thank you James for the prompt response.
Is it possible to insert the array at known index and shift what ever after that index one step down.
Thanks

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by