Creating a series of x-y plots
조회 수: 4 (최근 30일)
이전 댓글 표시
Hey, I want to make a set of x-y plots based on data with the following format:
"Tag Property-A Property-B
X1 A11 B11
X1 A12 B12
...........................
X2 A21 B21
..........................."
Properties A and B are the x and y variables. Each tag is matched with several pairs of A and B, and each plot should include data with a specific tag. Since there are a good many tags, it is impossible to manually separate the data. So is there any commands in Matlab that can be used to create such plots? I hope I have clearly stated my question. Thanks. Lin
P.S. I just realized the format couldn't display properly, so I'll briefly describe the data: there are three columns of data: Tag, Property A, Property B. Each tag encompasses a certain amount of x-y pairs, and the purpose is to make every one of the tags a plot showing the scattered x-y relationship.
A sample data file is attached.
댓글 수: 4
Image Analyst
2014년 9월 29일
I fixed the formatting for you, but please read this http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
채택된 답변
Chad Greene
2014년 9월 29일
If you have three columns, call them station, depth, and salinity, you could plot all the station 1 data as red pentograms, station 2 as blue squares, etc, like this:
plot(salinity(station==1),depth(station==1),'rp-');
hold on
plot(salinity(station==2),depth(station==2),'bs-');
plot(salinity(station==3),depth(station==3),'mo-');
plot(salinity(station==4),depth(station==4),'k^-');
plot(salinity(station==5),depth(station==5),'gx-');
legend('station 1','station 2','station 3','station 4',...
'station 5','location','southwest')
legend boxoff
box off
ylabel('depth (m)')
xlabel('salinity (psu??)')
set(gca,'ydir','reverse')
axis tight
댓글 수: 4
Chad Greene
2014년 9월 30일
Don't manually type plot lines 70 stations! If you want to do all of them on the same plot, this would work:
stationColors = jet(70); % creates 70 colors;
hold on;
for k = 1:70
plot(salinity(station==k),depth(station==k),...
'.-','color',stationColors(k,:));
end
box off
ylabel('depth (m)')
xlabel('salinity (psu??)')
set(gca,'ydir','reverse')
axis tight
Similarly, you could skip the loop and use scatter. You could even make the colors reflect something physically meaningful, rather than simply the station number. The profiles could be colored by latitude, or distance from the center of some gyre, or whatever interesting variable you're investigating.
If you only want to plot a single station, say, station number 15, you could use the example above like this:
k = 15; % <-- enter station number here
plot(salinity(station==k),depth(station==k),...
'.-','color',stationColors(k,:));
box off
ylabel('depth (m)')
xlabel('salinity (psu??)')
set(gca,'ydir','reverse')
axis tight
추가 답변 (1개)
Image Analyst
2014년 9월 29일
Just use readtable
t = readtable(xlsFullFileName);
Then extract the columns, use unique() to find unique tag names, then use logical indexing in a loop to extract rows for each tag in turn and plot. Let us know if you can't figure it out. Sorry, but I have to run off somewhere now.
댓글 수: 5
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!