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!