Graphs in MATLAB: Plotting n & t on Same Graph

In summary, the conversation discussed how to graph a function with respect to two different variables, n and t, using the MATLAB function num.m. The solution involved using the plot command and ensuring that all arrays being graphed had the same number of elements. A tutorial was also recommended for further assistance.
  • #1
sara_87
763
0

Homework Statement



If we have a function f with respect to t,
given:
h=a/n
t=i*h

so this means, t depends on n.
I have a function in MATLAB named num.m: where n is the only input and. My question is: if i num(10) i can generate a graph of t (x axis) against f (y axis) by the command: plot(t,f). and i can also generate a graph for n=80 by executing num(80)

but...how can i have them on the same graph?
i tried to plot them on the same graph, but i get an error: vectors must be of the same length.

Homework Equations





The Attempt at a Solution



Thanks in advance.
 
Physics news on Phys.org
  • #2
To get more than one equation on your graph, see Ch 3 in this tutorial, http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/getstart.pdf, especially p. 3-33, Adding More Data to the Graph.

From the error you're getting, your arrays are apparently different sized, meaning they have different numbers of elements in them. If you want to graph, say x vs. t and y vs. t, make sure that all three arrays have 80 (or however many) elements in them.
 
  • #3
thanks. i used it and it helped a lot.
:)
 

FAQ: Graphs in MATLAB: Plotting n & t on Same Graph

How do I plot two variables on the same graph in MATLAB?

To plot two variables, n and t, on the same graph in MATLAB, you can use the "plot" function and specify both variables as inputs. For example, you can use the code "plot(n,t)" to create a graph with n on the x-axis and t on the y-axis.

Can I customize the appearance of the graph?

Yes, you can customize the appearance of the graph by using various plot properties in MATLAB. These properties include color, line style, and marker style, which can be specified as additional inputs to the "plot" function. You can also add a title, axis labels, and a legend to the graph to make it more informative.

What is the difference between plotting n and t separately and plotting them on the same graph?

Plotting n and t separately will create two separate graphs, while plotting them on the same graph will show the relationship between the two variables. This allows you to see any patterns or correlations between n and t more easily.

How do I add multiple data sets to the same graph?

To add multiple data sets to the same graph, you can use the "hold on" command in MATLAB. This will allow you to plot multiple variables on the same graph without overwriting the previous data. You can also use the "hold off" command to stop adding new data sets to the graph.

Can I save the graph as an image or file?

Yes, you can save the graph as an image or file in MATLAB by using the "saveas" function. This function allows you to specify the file format and file name for the saved graph. You can also use the "print" function to save the graph as a high-resolution image in various file formats.

Similar threads

Replies
1
Views
1K
Replies
3
Views
1K
Replies
1
Views
1K
Replies
6
Views
2K
Replies
6
Views
2K
Replies
2
Views
416
Replies
1
Views
2K
Back
Top