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..
Star Strider
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
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.
Adam Danz
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
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
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 ExchangeTwo 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