Graphs in MATLAB: Plotting n & t on Same Graph

  • Thread starter Thread starter sara_87
  • Start date Start date
  • Tags Tags
    Graphs Matlab
Click For Summary
To plot both t and f on the same graph in MATLAB, ensure that the arrays for t and f have the same length, as the error indicates they currently do not. The relationship t = i*h, where h = a/n, shows that t is dependent on n, which must be accounted for when generating the data. When calling your function num(n), make sure it returns an array of the same size for both t and f. Referencing MATLAB documentation can provide additional guidance on adding multiple datasets to a single graph. Properly aligning the data arrays will resolve the issue and allow for successful plotting.
sara_87
Messages
748
Reaction score
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
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.
 
thanks. i used it and it helped a lot.
:)
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 11 ·
Replies
11
Views
1K
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
830