필터 지우기
필터 지우기

Plotting results of three different data sets on same Plot

조회 수: 38 (최근 30일)
Ben Brooke
Ben Brooke 2012년 4월 13일
댓글: Martin Llorens 2022년 11월 3일
Hi,
I would like to compare the velocity profiles of three different data sets, contained within three different folders. How would I go about writing the code for a function to import the three data sets and plot them all on the same graph so that they can be compared with one another. I would like to be able to change the name of the files to be imported in the code so it can reused for different examples.
I imagine this should be fairly simple, however I'm still very new to Matlab so getting a bit stuck.
Thanks

채택된 답변

laurie
laurie 2012년 4월 13일
How about:
load file1.mat
data1=data;
load file2.mat
data2=data
hold all
plot(data1)
plot(data2)
data1 and data2 must be the same length though I think.
About the different folders: I think if you add all the folders to the path (manually?) it should work fine.
Cheers
  댓글 수: 3
Ben Brooke
Ben Brooke 2012년 4월 13일
Thanks. I managed to make some alterations but used your basis. Cheers!
laurie
laurie 2012년 4월 13일
thanks :) i am glad i can both help and learn new things about matlab

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Vaibhav
Vaibhav 2012년 4월 13일
The code above would work. Another alternative is to
plot(x,y1,x,y2,x,y3)
If x is not same for all 3 sets, then
plot(x1,y1,x2,y2,x3,y3)
But x1,x2,x3 must be the same length.
  댓글 수: 1
Martin Llorens
Martin Llorens 2022년 11월 3일
But if i want to plot also a tendency line, how i would do it?

댓글을 달려면 로그인하십시오.


Matt Kindig
Matt Kindig 2012년 4월 13일
Depending on the format of the data sets, there are a variety of functions available to import the data. Look at the following to get you started (these are references to topics in Matlab help):
doc load
doc importdata
doc dlmread
doc textscan
To plot data:
doc plot
doc hold
To change the names of the files, I would probably have one of the function inputs be a cell array with the filenames, and have a for loop in the function to iterate through each data set and do the plotting.
doc cell
doc for

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by