Plotting yyasix in Matlab from csv file
이전 댓글 표시
Hi
I have csv file and want to plot in matlab, I am having difficulty in plotting that file because I have two columns of data and my x-axis is constant. With one y-axis i had plot the results but the issue is with two columns.I have attached the csv file, if any body can help me that, it would be great.
Thanks
답변 (3개)
Star Strider
2019년 5월 1일
편집: Star Strider
2019년 5월 1일
Try this:
D = xlsread('pce and power at 10k for lvt.csv');
figure
yyaxis left
plot(D(:,1), D(:,2))
yyaxis right
plot(D(:,3), D(:,4))
grid
legend('Column 2', 'Column 4', 'Location','S')
EDIT —
Using plotyy:
figure
[hAx,hLine1,hLine2] = plotyy(D(:,1),D(:,2), D(:,3),D(:,4));
hLine1.LineStyle = '-.';
hLine2.LineStyle = '-.';
ylabel(hAx(1),'HBM Current Level (A)','FontSize',15,'FontWeight','bold')
ylabel(hAx(2),'Column 4 Header','FontSize',15,'FontWeight','bold')
xlabel('Time (ns)','FontSize',15,'FontWeight','bold')
legend('Current waveform from a 1500V HBM pulse', 'Location','S')
title('ESD event for the HBM')
grid minor

댓글 수: 4
Syed Nawaz
2019년 5월 1일
Syed Nawaz
2019년 5월 1일
Star Strider
2019년 5월 1일
Add one of these after the plotyy call:
set(gca, 'XTick',D(:,1)) % X-Tick Values From File
set(gca, 'XTick',(min(D(:,1)):max(D(:,1)))) % Uninterrupted X-Tick Values
Choose the one that does what you want. The first one uses the values for the x-axis ticks from your file (Columns 1 and 3 are the same, and there is a gap between 3 and 6). The second one creates continuous x-ticks.
Set the y-tick values similarly:
yt1 = get(hAx(1), 'YTick');
ytickLeft = round(linspace(min(yt1), max(yt1), 15),1);
set(hAx(1), 'YTick', ytickLeft)
yt2 = get(hAx(2), 'YTick');
ytickRight = round(linspace(min(yt2), max(yt2), 15),2);
set(hAx(2), 'YTick', ytickRight)
Experiment to get the result you want.
Star Strider
2019년 5월 1일
My plotyy code now adds y-axis tick values. Experiment with the ‘ytickLeft’ and 'ytickRight’ linspace calls to get the axis results you want. (I suggest making the lengths — created by the last argument to linspace — the same value. Here, they are both 15 elements.)
Adam Danz
2019년 5월 1일
See my 3 comments to understand the changes I made.
plotData = importdata('pce and power at 10k for lvt.csv')
plotData.colheaders(1)
plotData.data(1)
figure(1)
clf
hold on
grid minor
yyaxis left %added this
plot(plotData.data(:,1),plotData.data(:,2),'*-','LineWidth',1.2) %removed color 'b'
title('ESD event for the HBM')
set(gca,'FontSize',18);
xlabel('Time (ns)','FontSize',15,'FontWeight','bold')
ylabel('HBM Current Level (A)','FontSize',15,'FontWeight','bold')
% added everything below
yyaxis right
plot(plotData.data(:,3),plotData.data(:,4),'*-','LineWidth',1.2)
% moved this down
legend({'Current waveform from a 1500V HBM pulse', 'Other thing'})

댓글 수: 9
Syed Nawaz
2019년 5월 1일
Adam Danz
2019년 5월 1일
Syed Nawaz's comment moved here
There is error poping up and there is nothing in the graph.
Undefined function or variable 'yyaxis'.
Error in Untitled3 (line 8)
yyaxis left %added this
Adam Danz
2019년 5월 1일
yyaxis is included in releases r2016a and later.
For earlier releases, use plotyy
plotyy(plotData.data(:,1),plotData.data(:,2),plotData.data(:,3),plotData.data(:,4))
Syed Nawaz
2019년 5월 1일
Adam Danz
2019년 5월 1일
You should only have one call to plotyy() and no calls to plot().
Feel free to share your updated code so we can take a look at it.
Syed Nawaz
2019년 5월 1일
Use the axes handles (output to plotyy) and set axis properties.
Here are a list of all axis properties and their definitions.
ph = plotyy(plotData.data(:,1),plotData.data(:,2),plotData.data(:,3),plotData.data(:,4));
axis(ph, 'tight') %set both axes as 'tight'
set(ph(1), 'yTick', -40:10:10, 'ylim', [-40 10])
set(ph(2), 'yTick', 0:.1:.8, 'ylim', [0, .8])

Syed Nawaz
2019년 5월 1일
Make sure you check out Star Strider's suggestion to use linspace() to create your ticks. I hard-coded them in my example just to quickly show how to set the axis parameters.
카테고리
도움말 센터 및 File Exchange에서 Two y-axis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!