Meaning of : in the parentheses

  • Thread starter jasoncurious
  • Start date
In summary, the conversation discussed the use of partial pivoting in a Matlab program. The colon operator was explained as a way to select entire rows or columns in a matrix. The exchange also provided a resource for further understanding of the operator.
  • #1
jasoncurious
8
0
Hi guys, I am currently doing a Matlab program for partial pivoting. I looked at my friend's example:

Code:
% Partial Pivoting
for i=1:n-1
for j = i+1:n
if (a(j,i)) > (a(i,i))
u=a(i,:);
a(i,:)=a(j,:);
a(j,:)=u;
v=b(i,1);
b(i,1)=b(j,1);
b(j,1)=v;
end
end
end

I was wondering what's the meaning of the : in the parentheses. Is it some sort of Matlab keyword? Thanks for helping
 
Physics news on Phys.org
  • #2
The colon stands for a whole line in the matrix. Observe:
Code:
octave:117> m=magic(4)
m =

   16    2    3   13
    5   11   10    8
    9    7    6   12
    4   14   15    1

octave:118> m(2,:)
ans =

    5   11   10    8

octave:119> m(:,2)
ans =

    2
   11
    7
   14
... see?
... so m(2,:) says to take the entire second row while the m(:,2) says take the second column.
http://volga.eng.yale.edu/sohrab/matlab_tutorial.html#selecting_parts_of_vectors_and_matrices__the_colon_operator
(Matlab works the same way...)
 
Last edited by a moderator:
  • #3
Thanks bro.
 
  • #4
No worries ;)
Generally, you can try out the confusing operations you see on some random matrix and see what happens ... the magic-square function is very useful for this.
 
  • #5


In this context, the colon (:) is used as an indexing operator in Matlab. It allows you to select a range of elements from a matrix or array. For example, in the line "u=a(i,:)", the colon is used to select all the elements in the i-th row of the matrix a. Similarly, in the line "v=b(i,1)", the colon is used to select the element in the i-th row and first column of the matrix b. It is not a keyword, but rather a useful tool for accessing specific elements in a matrix or array.
 

What is the meaning of the colon in parentheses?

The colon in parentheses typically indicates a clarification or additional information related to the preceding sentence or phrase. It can also be used to introduce a list or explanation.

Why do we use a colon in parentheses?

A colon in parentheses is used to provide a brief, concise explanation or clarification without interrupting the flow of the main sentence. It also helps to organize information in a clear and concise manner.

Is there a difference between using a colon or a comma in parentheses?

Yes, there is a difference. A colon in parentheses is used to introduce a list or explanation, while a comma is used to separate items in a list or to indicate a pause in a sentence.

Can a colon be used after a question mark in parentheses?

Yes, it is grammatically correct to use a colon after a question mark in parentheses. This is often seen in academic writing, where a question is followed by a clarification or explanation.

What are some common mistakes when using a colon in parentheses?

One common mistake is using a colon instead of a comma to separate items in a list. Another mistake is using a colon to introduce a list but not providing a list afterwards. It is also important to make sure the information after the colon is relevant and adds value to the preceding sentence.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
41
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
927
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Replies
5
Views
367
  • Programming and Computer Science
Replies
1
Views
935
Replies
27
Views
901
Back
Top