Matlab indexing within a matrx

  • MATLAB
  • Thread starter joanne34567
  • Start date
  • Tags
    Matlab
In summary, the speaker is struggling to use values in one column to select values from another set of columns for plotting in a matrix. They are seeking ideas on how to accomplish this, and are reminded that both columns must have the same size for the plot to work.
  • #1
joanne34567
12
0
So I have a dataset...
I am trying to use let's say values in column 1 to determine which values I need to plot from columns 5 and 6...
Reading about indexing in a matrix doesn't really help as it doesn't hint at how you might use values in one column to select values from another set of columns and I'm a bit stuck.
Any ideas?
 
Physics news on Phys.org
  • #2
Plot column 1 with column 6:

plot(col(:,1),col(:,6))

Keep in mind that the two columns must have the same size.

Matlab plots columns in a 1-1 relation, so it will plot the abscissa col(1,1) with the ordinate col(1,6), then the point (col(2,1),col(2,6)), etc.
 

1. How can I access a specific element within a matrix in Matlab?

To access a specific element within a matrix, you can use indexing. The syntax for indexing in Matlab is matrix(row, column), where row and column refer to the position of the element you want to access.

2. Can I use logical indexing in Matlab?

Yes, Matlab allows for logical indexing, which allows you to select elements from a matrix based on a logical condition. For example, you can use the logical operator == to select all elements equal to a certain value.

3. How do I assign a value to a specific element within a matrix?

To assign a value to a specific element within a matrix, you can use the same indexing syntax as accessing an element, but on the left side of an assignment statement. For example, matrix(row, column) = value.

4. Can I use a vector as an index for a matrix in Matlab?

Yes, you can use a vector as an index for a matrix in Matlab. This is known as linear indexing, where the vector represents the linear indices of the elements you want to select.

5. What happens if I try to access an element outside of the matrix dimensions in Matlab?

If you try to access an element outside of the matrix dimensions in Matlab, you will receive an error. It is important to ensure that your index values fall within the dimensions of your matrix to avoid errors.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
712
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • Linear and Abstract Algebra
Replies
12
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
697
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Back
Top