Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to swap x and y axis?

Subject: How to swap x and y axis?

From: Hongcheng

Date: 14 Nov, 2009 10:21:01

Message: 1 of 6

spectrogram() function plot the spectrogram which x axis is frequency and y axis is time. I want to plot a spectrogram figure whose x axis is time and y axis is frequency. How should I do?
Thanks!

Subject: How to swap x and y axis?

From: Wayne King

Date: 14 Nov, 2009 13:18:02

Message: 2 of 6

"Hongcheng " <yorkbluedream@gmail.com> wrote in message <hdm0ad$6fc$1@fred.mathworks.com>...
> spectrogram() function plot the spectrogram which x axis is frequency and y axis is time. I want to plot a spectrogram figure whose x axis is time and y axis is frequency. How should I do?
> Thanks!

Hi Hongcheng,

     t =0:0.001:2; % 2 secs @ 1kHz sample rate
      x = chirp(t,0,1,150); % Start @ DC, cross 150Hz at t=1sec
      F = 0:.1:100;
      [y,f,t,p] = spectrogram(x,256,250,F,1E3,'yaxis');
      surf(t,f,10*log10(abs(p)),'EdgeColor','none');
      axis xy; axis tight; colormap(jet); view(0,90);
      xlabel('Time');
      ylabel('Frequency (Hz)');

Wayne

Subject: How to swap x and y axis?

From: Jos

Date: 14 Nov, 2009 14:00:20

Message: 3 of 6

"Hongcheng " <yorkbluedream@gmail.com> wrote in message <hdm0ad$6fc$1@fred.mathworks.com>...
> spectrogram() function plot the spectrogram which x axis is frequency and y axis is time. I want to plot a spectrogram figure whose x axis is time and y axis is frequency. How should I do?
> Thanks!

help view

x = -pi:.01:pi ; plot(x,sin(x),'b-') ; % example plot
view(-90,90) % swap the x and y axis

hth
Jos

Subject: How to swap x and y axis?

From: Hongcheng

Date: 16 Nov, 2009 04:21:01

Message: 4 of 6

"Jos " <#10584@fileexchange.com> wrote in message <hdmd5k$j0m$1@fred.mathworks.com>...
> "Hongcheng " <yorkbluedream@gmail.com> wrote in message <hdm0ad$6fc$1@fred.mathworks.com>...
> > spectrogram() function plot the spectrogram which x axis is frequency and y axis is time. I want to plot a spectrogram figure whose x axis is time and y axis is frequency. How should I do?
> > Thanks!
>
> help view
>
> x = -pi:.01:pi ; plot(x,sin(x),'b-') ; % example plot
> view(-90,90) % swap the x and y axis
>
> hth
> Jos

Hi Jos,
I use your code, but the x axis is reversed. My x axis is time, so it can not be reversed.How to solve that problem?
Use this code, you will see the x axis is reversed.
x = 0:.01:pi ; plot(x,sin(x),'b-') ; % example plot
view(-90,90)

Subject: How to swap x and y axis?

From: Jos

Date: 16 Nov, 2009 12:48:01

Message: 5 of 6

"Hongcheng " <yorkbluedream@gmail.com> wrote in message <hdqjvd$clo$1@fred.mathworks.com>...
> "Jos " <#10584@fileexchange.com> wrote in message <hdmd5k$j0m$1@fred.mathworks.com>...
> > "Hongcheng " <yorkbluedream@gmail.com> wrote in message <hdm0ad$6fc$1@fred.mathworks.com>...
> > > spectrogram() function plot the spectrogram which x axis is frequency and y axis is time. I want to plot a spectrogram figure whose x axis is time and y axis is frequency. How should I do?
> > > Thanks!
> >
> > help view
> >
> > x = -pi:.01:pi ; plot(x,sin(x),'b-') ; % example plot
> > view(-90,90) % swap the x and y axis
> >
> > hth
> > Jos
>
> Hi Jos,
> I use your code, but the x axis is reversed. My x axis is time, so it can not be reversed.How to solve that problem?
> Use this code, you will see the x axis is reversed.
> x = 0:.01:pi ; plot(x,sin(x),'b-') ; % example plot
> view(-90,90)

You are right. Try reversing the direction:

x = 0:.01:pi ; plot(x,sin(x),'b-') ; % example plot
view(-90,90)
set(gca,'ydir','reverse')

Jos

Subject: How to swap x and y axis?

From: Nicole Prause

Date: 23 Nov, 2009 23:31:04

Message: 6 of 6

Thanks for the solution. Helpful archive! Odd that they would put time on the y to begin with, but perhaps it's a field difference.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us