command to create array and graph

Hi guys,
I am preparing for exams, doing practice questions and want to know if the commands I am using for a question are correct.
Matrix 3 rows, 5 columns
  • 16 456 22 85 93
  • 11 78 310 62 36
  • 1 66 23 67 405
Is the command to create this matrix
a = [16 456 22 85 93;11 78 310 62 36;1 66 23 67 405] ?
how would I graph the 3rd row or column? how can the grid of the graph be set to visable and the x and y axis to be included?
thank you :)

回答 (1 件)

Geoff Hayes
Geoff Hayes 2016 年 5 月 1 日

1 投票

Laura - yes, the command
a = [16 456 22 85 93;11 78 310 62 36;1 66 23 67 405]
will create the 3x5 matrix. To extract all of the elements of the third row, you can do
a(3,:)
and to access all the elements of the third column, you can do
a(:,3)
You can then plot this data however you want. See grid for displaying or hiding the axes grid lines.

3 件のコメント

Laura McHugh
Laura McHugh 2016 年 5 月 1 日
Great help Geoff!! - I now understand how to extract use the rows and columns - how would I write command to turn on the grid to provide labels for the X ('sample') and y ('value') axes ?
Geoff Hayes
Geoff Hayes 2016 年 5 月 1 日
Glad to have been able to help, Laura. As for turning on the grid lines, please see the documentation at grid. Labels for the x and y axes, see Add Title, Axis Labels, and Legend to a Graph.
Laura McHugh
Laura McHugh 2016 年 5 月 2 日
Thanks Geoff!!

サインインしてコメントする。

カテゴリ

質問済み:

2016 年 5 月 1 日

コメント済み:

2016 年 5 月 2 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by