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 Comment

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'})

Sign in to comment.

Answers (3)

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 Comments

Values on y-axis should be discrete,not like this
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.
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.)

Sign in to comment.

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 Comments

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))
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
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.
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'})
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])
Thanks a ton man.. you made my life much easier..
Adam Danz
Adam Danz on 1 May 2019
Edited: Adam Danz on 6 May 2019
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.

Sign in to comment.

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

Categories

Asked:

on 1 May 2019

Edited:

on 6 May 2019

Community Treasure Hunt

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

Start Hunting!