Matlab Concatenation Help: Resolving B([1 2], [1 3])

  • MATLAB
  • Thread starter gfd43tg
  • Start date
  • Tags
    matlab
In summary, the conversation discusses the use of matrix indexing in MATLAB and the confusion surrounding the notation. The notation B([1 2], [1 3]) means selecting rows 1 and 2, and columns 1 and 3 of the matrix B. This can be done in any order, as shown in the example with B([2 1], [3 2]). The conversation also mentions an example with a picture for better understanding.
  • #1
gfd43tg
Gold Member
950
50
Hello,

I am curious why the following concatenation is not working the way I thought it would.

Code:
B = [0 5 1; 2 4 3]

B =

     0     5     1
     2     4     3

Code:
B([1 2], [1 3])

ans =

     0     1
     2     3

I don't really understand what this command is extracting from the matrix and how it is arranging it. It looks like B([1 2]) gets the 1st and 2nd element of B, but then the [1 3] part is not the 1st and 3rd element.
 
Physics news on Phys.org
  • #2
The notation means B (a list of rows , a list of columns).

So if the original matrix was ##\begin{matrix} b_{11} & b_{12} & b_{13} \\ b_{21} & b_{22} & b_{23} \end{matrix}##, you are selecting rows 1 and 2, and columns 1 and 3, which is
##\begin{matrix} b_{11} & b_{13} \\ b_{21} & b_{23} \end{matrix}##

Note you can select rows and columns in any order, so B([2 1], [3 2]) would give ##\begin{matrix} b_{23} & b_{22} \\ b_{13} & b_{12} \end{matrix}##

There is an example with a picture here: http://www.mathworks.co.uk/company/newsletters/articles/matrix-indexing-in-matlab.html
 
  • Like
Likes 1 person
  • #3
Thanks, and great example. That is really tricky when you do everything backwards like that. I see how that one is, and I see the algorithm for how to insert into the matrix. I get conceptually now, but the algorithm can be a backup in case I have a blank out on the exam.

B([2 1], [3 2]) = ##b_{23}##
B([2 1], [3 2]) = ##b_{22}##
B([2 1], [3 2]) = ##b_{13}##
B([2 1], [3 2]) = ##b_{12}##
 
Last edited:

1. What is "Matlab Concatenation"?

Matlab concatenation is the process of combining multiple arrays or matrices into a single array or matrix, usually by joining them together along a specific dimension.

2. What does "B([1 2], [1 3])" mean in Matlab concatenation?

"B([1 2], [1 3])" refers to a specific subset of elements from the array B. The first set of indices [1 2] indicates the rows to be selected, while the second set of indices [1 3] indicates the columns to be selected. This means that the resulting array will consist of the elements in the first and second rows, and the first and third columns of B.

3. How do I resolve "B([1 2], [1 3])" in Matlab concatenation?

To resolve "B([1 2], [1 3])", you will need to specify the array B and the specific rows and columns that you want to select. This can be done by using the colon operator ":" to select all rows or columns, or by specifying the specific indices you want to select.

4. Can I concatenate more than two arrays in Matlab?

Yes, you can concatenate more than two arrays in Matlab. You can do this by using the "cat" function, which allows you to concatenate arrays along a specified dimension. You can also use the "vertcat" or "horzcat" functions to concatenate arrays vertically or horizontally, respectively.

5. What is the purpose of concatenation in Matlab?

The purpose of concatenation in Matlab is to combine multiple arrays or matrices into a single array or matrix, which can be useful for data analysis and manipulation. This allows for easier handling and processing of large datasets, and can also help in creating new arrays or matrices with desired dimensions and structures.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
553
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
985
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
116
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top