how to fit an array in matrix?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Abdulaziz Abutunis
am 8 Okt. 2015
Beantwortet: Image Analyst
am 8 Okt. 2015
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
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 8 Okt. 2015
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.
0 Kommentare
Weitere Antworten (1)
James Tursa
am 8 Okt. 2015
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
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!