Hello,
I have attached the simulation result and csv file but I want to plot these graphs in matlab after plotting the graps in matlab my Y-axis is missing. This is my code I need help please where i went wrong.
plotData = importdata('nmosesd.csv')
plotData.colheaders(1)
plotData.data(1)
figure(1)
clf
hold on
grid minor
hLine(1)=plot(plotData.data(:,1),plotData.data(:,2),'*-r','LineWidth',2)
hLine(2)=plot(plotData.data(:,3),plotData.data(:,4),'p-b','LineWidth',2)
hLine(3)=plot(plotData.data(:,5),plotData.data(:,6),'o-k','LineWidth',2)
hLine(4)=plot(plotData.data(:,7),plotData.data(:,8),'^-g','LineWidth',2)
title('Output Voltage at 10K\Omega')
set(gca,'FontSize',11);
xlabel('Time','FontSize',11,'FontWeight','bold')
ylabel('Voltage','FontSize',11,'FontWeight','bold')
legend([hLine(1) hLine(2) hLine(3) hLine(4)],'Input Power for Low Vth transistor','Current','Input Power for High Vth transistor', 'Input Power for Standard Vth transistor')

 Respuesta aceptada

Star Strider
Star Strider el 2 de Mayo de 2019

1 voto

Try this:
plotData = importdata('nmosesd.csv')
plotData.colheaders(1)
plotData.data(1)
figure(1)
clf
hold on
grid minor
hLine(1)=plot(plotData.data(:,1),plotData.data(:,2),'*-r','LineWidth',2)
hLine(2)=plot(plotData.data(:,3),plotData.data(:,4),'p-b','LineWidth',2)
hLine(3)=plot(plotData.data(:,5),plotData.data(:,6),'o-k','LineWidth',2)
hLine(4)=plot(plotData.data(:,7),plotData.data(:,8),'^-g','LineWidth',2)
hold off
yyaxis right % Add Right Y-Axis
yt = get(gca, 'YTick'); % Get Default Y-Yick Values
newyt = linspace(min(yt), max(yt), 12); % Create New Right Y-Tick Values
newytl = linspace(-100, 1000, numel(newyt)); % Create New Right Y-Tick Labels
set(gca, 'YTick',newyt, 'YTickLabel',newytl); % Set New Right Y-Tick Labels
title('Output Voltage at 10K\Omega')
set(gca,'FontSize',11);
xlabel('Time','FontSize',11,'FontWeight','bold')
ylabel('Voltage','FontSize',11,'FontWeight','bold')
I do not have your data to work with. This works on my test plot.

13 comentarios

Rai
Rai el 2 de Mayo de 2019
Editada: Rai el 2 de Mayo de 2019
Thank you for yourr answer. but it was not working for me both x and y axis got blank and there is one error :
Undefined function or variable 'yyaxis'.
Error in nmos (line 13)
yyaxis right % Add Right Y-Axis
My matlab edition is R2015a: I also attached my csv file.
Star Strider
Star Strider el 2 de Mayo de 2019
My pleasure.
The yyaxis function appeared first in R2016a.
To use plotyy, you would do something like this:
x = 1:10;
y1 = 2*exp(-0.4*x);
y2 = 2*exp(-0.5*x);
y3 = 2*exp(-0.6*x);
y4 = 2*exp(-0.7*x);
figure
[Ax,H1,H2] = plotyy(x, y1, x, y2);
hold on
plot(x, y3, x, y4)
hold off
yt = get(Ax(2), 'YTick'); % Get Default Y-Yick Values
newyt = linspace(min(yt), max(yt), 12); % Create New Right Y-Tick Values
newytl = linspace(-100, 1000, numel(newyt)); % Create New Right Y-Tick Labels
set(Ax(2), 'YTick',newyt, 'YTickLabel',newytl); % Set New Right Y-Tick Labels
I am not certain the plotyy would work with your code as you posted it, so I will let you adapt your data to this code.
Rai
Rai el 2 de Mayo de 2019
The code which you write where I have to make changes? I try to make same changes in the exponential but still not geeting any success
Star Strider
Star Strider el 2 de Mayo de 2019
Plot them as:
figure
[Ax,H1,H2] = plotyy(plotData.data(:,1),plotData.data(:,2), plotData.data(:,3),plotData.data(:,4));
hold on
plot(plotData.data(:,5),plotData.data(:,6), 'o-k', plotData.data(:,7),plotData.data(:,8),'^-g')
hold off
H1.LineStyle = '*-r';
H2.LineStyle = 'p-b';
hold off
yt = get(Ax(2), 'YTick'); % Get Default Y-Yick Values
newyt = linspace(min(yt), max(yt), 12); % Create New Right Y-Tick Values
newytl = linspace(-100, 1000, numel(newyt)); % Create New Right Y-Tick Labels
set(Ax(2), 'YTick',newyt, 'YTickLabel',newytl); % Set New Right Y-Tick Labels
That should work. (I cannot test it because I do not have your data.)
Rai
Rai el 3 de Mayo de 2019
After I write your code still the YY-axis current label is missing and x-axis points are not correct. I also try to make legend but it genrate some error. I also attach my CSV data file please checkesd.PNG
Star Strider
Star Strider el 3 de Mayo de 2019
Try this:
[plotData,S] = xlsread('nmosesd.csv');
figure
[Ax,H1,H2] = plotyy(plotData(:,1),plotData(:,2), plotData(:,3),plotData(:,4));
hold on
plot(plotData(:,5),plotData(:,6), 'o-k', plotData(:,7),plotData(:,8),'^-g')
hold off
H1.LineStyle = '-.';
H2.LineStyle = '--';
hold off
ylabel(Ax(1), 'V(V)')
ylabel(Ax(2), 'I(mA)');
legend('Low Vth', 'Current', 'High Vth', 'Standard Vth') % Create Legend
ytr = get(Ax(2), 'YTick'); % Get Default Right Y-Yick Values
newytr = linspace(min(ytr), max(ytr), 12); % Create New Right Y-Tick Values
newytrl = linspace(-100, 1000, numel(newytr)); % Create New Right Y-Tick Labels
set(Ax(2), 'YTick',newytr, 'YTickLabel',newytrl); % Set New Right Y-Tick Labels
ytl = get(Ax(1), 'YTick'); % Get Default Left Y-Yick Values
newytl = linspace(min(ytl), max(ytl), 12); % Create New Left Y-Tick Values
newytll = round(newytl,1); % Create New Left Y-Tick Labels
set(Ax(1), 'YTick',newytl, 'YTickLabel',newytll); % Set New Left Y-Tick Labels
xt = get(gca, 'XTick');
set(gca, 'XTick',xt, 'XTickLabel',xt*1E+6)
xlabel('Time (ns)')
producing:
CVS yy-axis plot - 2019 05 02.png
Rai
Rai el 3 de Mayo de 2019
Editada: Rai el 3 de Mayo de 2019
Thank you for help I am geeting the desired graph.. But there is one problem I have to add markes for the other two graphs but it will generate error when ever I try to do it. Also is there any way i make my graphs LineWidth more than this. I use some commands but it will generate errors. I want to my graphs look like this: Please tell me where is problem in code
[plotData,S] = xlsread('nmosesd.csv');
figure
[Ax,H1,H2] = plotyy(plotData(:,7),plotData(:,8), plotData(:,3),plotData(:,4));
hold on
grid minor
plot(plotData(:,5),plotData(:,6), 'o-k', plotData(:,1),plotData(:,2),'^-g')
hold off
H1.LineStyle = '-';
H2.LineStyle = '--';
hold off
ylabel(Ax(1), 'V(V)')
ylabel(Ax(2), 'I(mA)');
legend('Low Vth', 'Current', 'High Vth', 'Standard Vth') % Create Legend
ytr = get(Ax(2), 'YTick'); % Get Default Right Y-Yick Values
newytr = linspace(min(ytr), max(ytr), 12); % Create New Right Y-Tick Values
newytrl = linspace(-100, 1000, numel(newytr)); % Create New Right Y-Tick Labels
set(Ax(2), 'YTick',newytr, 'YTickLabel',newytrl); % Set New Right Y-Tick Labels
ytl = get(Ax(1), 'YTick'); % Get Default Left Y-Yick Values
newytl = linspace(min(ytl), max(ytl), 12); % Create New Left Y-Tick Values
newytll = round(newytl,1); % Create New Left Y-Tick Labels
set(Ax(1), 'YTick',newytl, 'YTickLabel',newytll); % Set New Left Y-Tick Labels
xt = get(gca, 'XTick');
set(gca, 'XTick',xt, 'XTickLabel',xt*1E+6)
xlabel('Time (ns)')
Star Strider
Star Strider el 3 de Mayo de 2019
Those are the constraints of the plotyy function. The only way I can think of to add markers to the other plots, since plotyy only permits certain line styles, is to plot the marker specifically in another plot call. So if you want to add green upward-pointing tirangles to ‘Standard Vth’, use this:
plot(plotData(:,7),plotData(:,8),'^g')
That should work.
Rai
Rai el 3 de Mayo de 2019
I try this but it was not working if I leave the markers it still okay but the line width is too samll. Is there any way I change the widths of all graphs.
Star Strider
Star Strider el 3 de Mayo de 2019
That does not appear to ba an option with plotyy.
Rai
Rai el 3 de Mayo de 2019
okay thank so much Strider for your help and time.
Star Strider
Star Strider el 3 de Mayo de 2019
My pleasure.
Rai
Rai el 3 de Mayo de 2019
I try to use 'bold' command to make my all three axis to be more visible but no success for me. Is it possible to it them bold? or not. I need help regarding bold command in the code where I have to do it

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

Rai
el 2 de Mayo de 2019

Comentada:

Rai
el 3 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by