MATLAB How to Use Column Values for Plotting in Matlab?

  • Thread starter Thread starter joanne34567
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
To plot values from specific columns in a dataset based on the values in another column, it's essential to ensure that the columns being plotted have the same size. In MATLAB, you can use the command "plot(col(:,1), col(:,6))" to create a plot where the first column serves as the x-axis and the sixth column as the y-axis. This command establishes a one-to-one relationship between the values in the specified columns, plotting each point accordingly. Understanding how indexing works in matrices is crucial for effectively selecting and visualizing data from different columns based on criteria from another column.
joanne34567
Messages
12
Reaction score
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
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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
7
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K