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

댓글 수: 1

Syed Nawaz
Syed Nawaz 2019년 5월 1일
The code i am using is
plotData = importdata('11.csv')
plotData.colheaders(1)
plotData.data(1)
figure(1)
clf
hold on
grid minor
plot(plotData.data(:,1),plotData.data(:,2),'*-b','LineWidth',1.2)
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')
legend({'Current waveform from a 1500V HBM pulse'})

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

답변 (3개)

Star Strider
Star Strider 2019년 5월 1일
편집: Star Strider 2019년 5월 1일

0 개 추천

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
Plotting yyasix in Matlab from csv file - 2019 05 01.png

댓글 수: 4

Syed Nawaz
Syed Nawaz 2019년 5월 1일
Values on y-axis should be discrete,not like this
Syed Nawaz
Syed Nawaz 2019년 5월 1일
This is for x-axis, I am talking about y-axis..
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
Star Strider 2019년 5월 1일
See my previous Comment.
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
Adam Danz 2019년 5월 1일

0 개 추천

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
Syed Nawaz 2019년 5월 1일
I am using R2015a matlab edition.
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
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
Syed Nawaz 2019년 5월 1일
I am still getting i don't know what.. My exact result unfortunately should be like the one you have plotted but I am getting this
Adam Danz
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
Syed Nawaz 2019년 5월 1일
Thank you very much... I need to have discrete value on y-axis like the one you have plotted in above graph.. This is the result i am getting now in attached file
plotData = importdata('pce and power at 10k for lvt.csv')
plotData.colheaders(1)
plotData.data(1)
figure(1)
clf
hold on
grid minor
title('PCE and Input Power for Lvt')
set(gca,'FontSize',18);
xlabel('Input Power','FontSize',15,'FontWeight','bold')
ylabel('Avaiable Input Power','FontSize',15,'FontWeight','bold')
ylabel('PCE','FontSize',15,'FontWeight','bold')
plotyy(plotData.data(:,1),plotData.data(:,2),plotData.data(:,3),plotData.data(:,4))
legend({'PCE', 'Input Power'})
Adam Danz
Adam Danz 2019년 5월 1일
편집: Adam Danz 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
Syed Nawaz 2019년 5월 1일
Thanks a ton man.. you made my life much easier..
Adam Danz
Adam Danz 2019년 5월 1일
편집: Adam Danz 2019년 5월 6일
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.

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

Syed Nawaz
Syed Nawaz 2019년 5월 1일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Two y-axis에 대해 자세히 알아보기

질문:

2019년 5월 1일

편집:

2019년 5월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by