# Assigning matrices

**URL:** <https://discourse.julialang.org/t/assigning-matrices/99342>\
**Category:** New to Julia\
**Created:** [May 24, 2023, 4:57pm UTC](https://discourse.julialang.org/t/assigning-matrices/99342 "2023-05-24T16:57:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RDuarte](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@RDuarte](https://discourse.julialang.org/u/RDuarte)\
**Post date:** [May 24, 2023, 4:57pm UTC](https://discourse.julialang.org/t/assigning-matrices/99342/1 "2023-05-24T16:57:10Z")

</div>

Dear all;

I’m new in Julia and I’m trying to index one matrix to another.  
Let’s say, I have a matrix A of zero (242x970) and I want to assign a Matrix B,C and D in a specific part of A.

A=zeros(M+1,nf+1);  
A[2:M+1,2:nf+1]=B;  
A(1,2:nf+1) = C;  
A(2:M+1,1) = D;

M and nf are 241 and 969, respectively.

I can assign B but I’m getting errors when trying to assign C and D.  
Can you help me identify what I’m doing wrong.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 24, 2023, 5:13pm UTC](https://discourse.julialang.org/t/assigning-matrices/99342/2 "2023-05-24T17:13:13Z")

</div>

You’re using parenthesis instead of brackets for those two?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 24, 2023, 6:30pm UTC](https://discourse.julialang.org/t/assigning-matrices/99342/3 "2023-05-24T18:30:24Z")

</div>

In addition to the syntax error @lmiq noted above, see: [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757) … in particular, **quote** your code and post **runnable** code snippets (e.g. provide values for `M`, `nf`, `B`, `C`, and `D`, even if they are just random numbers).

---

<div class="post-metadata">

**Author:** ![RDuarte](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@RDuarte](https://discourse.julialang.org/u/RDuarte)\
**Post date:** [May 24, 2023, 10:09pm UTC](https://discourse.julialang.org/t/assigning-matrices/99342/4 "2023-05-24T22:09:04Z")

</div>

Thank you very much!

---

<div class="post-metadata">

**Author:** ![ronubi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronubi/32/4085_2.png) [@ronubi](https://discourse.julialang.org/u/ronubi)\
**Post date:** [May 24, 2023, 10:59pm UTC](https://discourse.julialang.org/t/assigning-matrices/99342/5 "2023-05-24T22:59:37Z")

</div>

Also please mark the reply by @lmiq as the solution, to close out this thread.
