Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problem with graph in Matlab

  1. Jul 5, 2012 #1
    I have climate data that I am plotting in Matlab with a script. The relevant code for this problem, I think, is this:

    Code (Text):

    lon = reshape(grid_txt_lon,144,73);
    lon(lon>180) = lon(lon>180) - 360;
    lon = [lon(74:144,:);lon(1:73,:)];
    lat = reshape(grid_txt_lat,144,73);
    deg = reshape(degree,144,73);
    deg = [deg(74:144,:);deg(1:73,:)];
     
    The map is divided in a grid of 2.5 degrees each, so the 144 longitude comes out to 360 degrees and the 73 latitude comes out to 182.5 degrees. I guess the latitude has one degree overlap. Using these values, I get a plot such as this:

    http://img36.imageshack.us/img36/479/ex1pr.jpg [Broken]

    But this isn't what I need, what I need is to plot a band of ±40 degrees (using different data) around the equator. So, I adjust the code to these values:

    Code (Text):

    lon = reshape(grid_txt_lon,144,[B][U]33[/U][/B]);
    lon(lon>180) = lon(lon>180) - 360;
    lon = [lon([B][U]34[/U][/B]:144,:);lon(1:[B][U]33[/U][/B],:)];
    lat = reshape(grid_txt_lat,144,[B][U]33[/U][/B]);
    deg = reshape(degree,144,[B][U]33[/U][/B]);
    deg = [deg([B][U]34[/U][/B]:144,:);deg(1:[B][U]33[/U][/B],:)];
     
    Changes emphasized. It works somewhat, but the graph becomes screwed up:

    http://img803.imageshack.us/img803/6199/ex2u.jpg [Broken]

    Exactly at 2*40, or 80 degrees, it starts doing weird things. Is there a problem in the way I adjusted the code perhaps?
     
    Last edited by a moderator: May 6, 2017
  2. jcsd
  3. Jul 5, 2012 #2
    I played around with it some more and adjusted the adjusted code in the following way, changes emphasized again:

    Code (Text):

    lon = reshape(grid_txt_lon,144,33);
    lon(lon>180) = lon(lon>180) - 360;
    lon = [lon([B][U]74[/U][/B]:144,:);lon(1:[B][U]73[/U][/B],:)];
    lat = reshape(grid_txt_lat,144,33);
    deg = reshape(degree,144,33);
    deg = [deg(34:144,:);deg(1:33,:)];
     
    This results in the following graph, which looks more like what you'd expect:

    http://img687.imageshack.us/img687/3705/ex3w.jpg [Broken]

    But how can I be sure this still reflecs reality and doesn't just look correct due to my tweaks to the code??
     
    Last edited by a moderator: May 6, 2017
  4. Jul 9, 2012 #3
    I have one thing I'm not sure of,

    Is the data covering the entire surface, and do you want it to be cropped for the purposes of an image, or does the data only cover your equatorial band of interest, and are you trying to make sure it is overlaid onto the world map with the correct scaling?

    If it's the former then I think this can be solved at the plotting level, depending on what code you're using, eg. by adjusting the pcolor face alpha values depending on the region you want to be omitted from the image. But the specifics will depend on the plotting code.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Problem with graph in Matlab
  1. Matlab graph (Replies: 14)

Loading...