Plot two variables as a function of the third one

Click For Summary

Discussion Overview

The discussion revolves around plotting multiple curves in a 2D graph using MATLAB, where the curves represent the relationship between two variables as a function of a third variable. Participants explore methods to visualize data with multiple readings across different conditions, specifically focusing on how to represent these relationships without resorting to 3D plots or complex curve fitting.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • Prasad M. Rao seeks guidance on plotting multiple curves in MATLAB, specifically wanting to visualize data for different days of the week without creating a 3D graph.
  • Some participants suggest using MATLAB's 3D plotting features, while others clarify the need for a 2D representation with multiple curves.
  • One participant proposes a method to plot multiple curves using arrays for different days, indicating how to structure the data for plotting.
  • Prasad expresses difficulty in applying suggested mathematical relationships to raw data, emphasizing the need for practical coding assistance.
  • Another participant suggests storing the independent variable as a column vector and the dependent variables in a two-dimensional array to facilitate plotting without curve fitting.
  • Prasad describes a more complex scenario involving three variables and requests help with plotting X vs. Y at discrete points of Z, indicating the need for loops and specific MATLAB commands.

Areas of Agreement / Disagreement

Participants generally agree on the need to plot multiple curves in a 2D graph but present different methods and approaches to achieve this. There is no consensus on the best approach, as participants have varying levels of familiarity with MATLAB and different interpretations of how to handle the data.

Contextual Notes

Participants discuss the challenges of working with large datasets and the limitations of curve fitting in their specific contexts. There are unresolved questions regarding the best methods to manipulate and visualize the data effectively.

Who May Find This Useful

This discussion may be useful for individuals looking to plot multiple datasets in MATLAB, particularly those dealing with time series data or multiple conditions in experimental settings.

XLR8RPM
Messages
5
Reaction score
0
Hello,

I want to plot a curve with variables along the X & Y axis.
But I also want the plot to show multiple curves as a function of another third variable.
For example, if I'm plotting a curve of fruits vs. cost, I would get one curve.
But how to plot it for say, seven days of the week, thus showing seven curves in the same graph.
I would be doing this Matlab.
So if someone could guide me with the codes.
Hoping for a reply.

Thanks,
Prasad M. Rao.
 
Physics news on Phys.org
You will get three dimensional graph since three variables are involved.
you can use 3d plot feature in Matlab to do that
 
No I don't want the graph to be 3D, I want it to be 2D but consist of multiple curves, the multiplicity being a function of the third variable for example, 7 curves for 7 days of the week.
 
Ok then you can do like this
plot(x,y1,x,y2,x,y3)

Here y1 is array of costs of all fruits on day 1 y2 cost on day 2 etc.,
 
Hey n.karthick thanks for replying so quickly.

Thanks for the advice, but here the variables x, y & z are columns of data with more than a thousand readings., how do I work around that ??
Can you post a sample code in Matlab.

Thanks,
Prasad M. Rao.
 
Let us assume the relation between 1st variable and 2nd variable in day 1 as
y=2*x^2
and in day 2 as
y=2.5*x^3
You can store 2nd variable in day1 in the variable y1 and day2 in y2
so y1=2*x (day1) and y2=2.5*x (day2) and so on.
Now you can plot 2D curve for all days like this
plot(x,y1,x,y2...)

As you mentioned if number of days are many you can do like this

x=[2 3 ]; % enter values of x
n=2;
m=2;
for i=1:n % n=no of days
for j=1:m %length of x
if i==1 % day 1 relation
y(i,j)=2*x(j)^2;
end
if i==2 % day 2 relation
y(i,j)=2.5*x(j)^3;
end
end
plot(x,y(i,:))
hold on % This will hold the current figure and plot the next values in same figure
end
 
Hey n.karthick, once again thanks for replying.
The relation that you suggested is very very difficult in my case, since I'm dealing with raw data and curve fitting is very difficult in my case and I will lose the essence of the data entirely.
Somebody elsewhere suggested the 'unique' and 'sort' functions.
Can you help me out with those codes.
I'm kinda new to Matlab codes :(

Thanks,
Prasad M. Rao.
 
What I meant is you can store independent variable as a column vector say x and other two variables as a two dimensional array say y, in which first column of y represents second variable and second column contains third variable. So you can plot II and III variable as a function of I variable. (This way there is no need for curve fitting). Is there any difficulty in this method? If you can explain your problem in detail you may get answer
 
Hey n.kartick I really need your help.
Apologies for the delay.
Lets see how helpful I cane be in my problem.
I have three variables say X, Y and Z.
I need to plot X vs. Y.
Now the problem:
1. Y is changing, so is Z.
So now what I need is the graph of X vs. Y at different Z.
2. Now all the variables (X,Y & Z) have thousands of values in them, but I would like the graphs at just some discrete points of Z.
3. OK I know that the graph of X vs. Y is a curve. So now all I want is multiple graphs on the same page of X vs. Y at different Z.
The people who know the exact code, said that I needed to use one or two for loops, the plot and the hold commands.
Please need help on this.
Thanks!
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K