Hi, I have data as bellow
x = [ 0 1 2 3 4 5 6 7 8 9 10]
V= [0 2 4 6 8 10 12 14 16 18 20]
I=V/0.5;
I wan to plot (x,V), and (x,I) on the same plot, now since both v and I carry same information all I want is to plot only (x,V) and show another Y axis on right corresponding to I.
Think of it as if you plot a variable say pressure (P) with tepmerature (t), plot (t,P) but you want two Y axis representing pressure in two different units say. mbar and torr. Am I able to explain myself?

 Risposta accettata

Samir
Samir il 2 Feb 2019

0 voti

This is what I wanted, check this file.
Let me know if there is a cleaner native matlab way of doing this.
Best Regards
Samir

Più risposte (1)

madhan ravi
madhan ravi il 30 Gen 2019

0 voti

doc yyaxis

8 Commenti

doc plotyy % for older version of matlab
Samir
Samir il 30 Gen 2019
Cant find.
I dont want two plots, I wont just one data plot (x,V) and two y axis one represents V and other I. not two lines.
madhan ravi
madhan ravi il 30 Gen 2019
Modificato: madhan ravi il 30 Gen 2019
First try the solutions suggested and then come back without trying you are wasting your time and others as well upload a sample picture of the desired graph so that it's clear what you are trying to do!
Does the below do what you want if not I have no idea what you want :
yyaxis left
plot(x,V)
ylabel('V')
yyaxis right
ylabel('I')
Samir
Samir il 30 Gen 2019
I havent tried, but this wont get the y tick labels right.
Samir
Samir il 30 Gen 2019
Capture.JPG
yyaxis left
plot(x,V)
ylim([0 10])
yticks(0:2:10)
xlabel('x')
ylabel('V')
yyaxis right
xlabel('x')
ylabel('I')
ylim([0 20])
yticks(4:4:20)
Samir
Samir il 30 Gen 2019
Modificato: Samir il 30 Gen 2019
I understand but this is just an example, the tick labels wont be the same every time. I want the plot to read x and V from the variables which may vary in every iteration and so can I which is supposed to be on the right Y axis. Also the relationship can be complicated then presented. So I wan something similar to plotyy(x,V,x,I) but there is no need for two lines. Jsut want to present I on right Y axis so one can read either V or I from the same plot.
Samir
Samir il 30 Gen 2019
Modificato: Samir il 30 Gen 2019
think of it as if you plot a variable say pressure (P) with tepmerature (t), plot (t,P) but you want two Y axis representing pressure in two different units say. mbar and torr. Am I able to explain myself?

Accedi per commentare.

Tag

Richiesto:

il 30 Gen 2019

Risposto:

il 2 Feb 2019

Community Treasure Hunt

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

Start Hunting!

Translated by