Concatenating 2D Array: Adding Rows | Step-by-Step Guide for Problem 1(d)"

  • Thread starter Thread starter gfd43tg
  • Start date Start date
  • Tags Tags
    2d Array
Click For Summary
SUMMARY

The discussion focuses on concatenating a 2D array in MATLAB, specifically addressing how to insert a row into an existing matrix. The user demonstrates their progress with a matrix A1 and successfully concatenates a new row at the end using the command A4 = [A1; C]. However, they seek guidance on inserting a row at a specific position, particularly the second row, and are advised to utilize the zeros command for efficiency. The solution involves extracting relevant rows from A1 and combining them with the new row.

PREREQUISITES
  • Basic understanding of MATLAB syntax and array manipulation
  • Familiarity with matrix concatenation techniques in MATLAB
  • Knowledge of the zeros function in MATLAB for creating zero matrices
  • Experience with indexing and slicing arrays in MATLAB
NEXT STEPS
  • Research MATLAB array indexing techniques for inserting rows
  • Learn about the zeros function in MATLAB for efficient matrix creation
  • Explore advanced matrix manipulation functions in MATLAB
  • Practice concatenating matrices with varying dimensions in MATLAB
USEFUL FOR

Students and educators in mathematics or engineering fields, MATLAB users looking to enhance their skills in matrix manipulation, and anyone working on homework or projects involving 2D arrays in MATLAB.

gfd43tg
Gold Member
Messages
949
Reaction score
48

Homework Statement


I'm working on problem 1, specifically part (d) in the attached PDF file. I will show my code for (a) - (c) so you can see where I am coming from

Homework Equations


The Attempt at a Solution



(a)
Code:
  A1 = [1.3 5.2; 7.4 3.8; 9 2]

A1 =

    1.3000    5.2000
    7.4000    3.8000
    9.0000    2.0000
(b)
Code:
A1(2)

ans =

    7.4000

(c)
Code:
B = [1 1 1];
A3 = [A1 B']

A3 =

    1.3000    5.2000    1.0000
    7.4000    3.8000    1.0000
    9.0000    2.0000    1.0000

(d)
I don't know how to add a row into the array for any given row. I know if I wanted to add for example [0 0] to the end of the row

Code:
C = [0 0]

C =

     0     0

A4 = [A1; C]

A4 =

    1.3000    5.2000
    7.4000    3.8000
    9.0000    2.0000
         0         0

but I just need to move that [0 0] into the second row
 

Attachments

Last edited:
Physics news on Phys.org
I think you have to use [xxx; C ; yyy] where xxx and yyy extract the relevant rows from A1.

Also the problem told you to use the zeros command, which you could put in place of making the intermediate matrix C.
 
  • Like
Likes   Reactions: 1 person

Similar threads

  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
Replies
1
Views
2K
Replies
2
Views
3K
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K