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:
calling function to make multiple scatterm plots

Subject: calling function to make multiple scatterm plots

From: Jonathan W Smith

Date: 12 Sep, 2013 23:30:15

Message: 1 of 9

Hello:

I have the following set of statements:


function data = read_iasi_netcdf_f(folder, varName)

varNames ={'Latitude','Longitude','Pressure','O3_MR','Skin_Temperature','CO_MR','Temperature','CH4_MR','HNO3_MR','N2O_MR'};

varName = {'LAT','LON','P','ozone','skin_t','CO','T','CH4','HNO3','N2O'};

% % Load Script

iasi_files = dir([folder,'/*.nc']);

% Variable names inside IASI File

num_iasi_files = length(iasi_files);

    % Opening each variable in IASI netcdf file

 % LAT{i_files} = ncread([folder '/' iasi_files(i_files).name],varNames{1});



%Data structure

for i_files = 1:num_iasi_files;

    levs = [47 55 61 70 82 85 91 94];

    % Opening each variable in IASI netcdf file

    LAT{i_files} = ncread([folder '/' iasi_files(i_files).name],varNames{1});

    LON{i_files} = ncread([folder '/' iasi_files(i_files).name],varNames{2});

    P{i_files} = ncread([folder '/' iasi_files(i_files).name],varNames{3});

    ozone{i_files} = ncread([folder '/' iasi_files(i_files).name],varNames{4});

    skin_t{i_files} = ncread([folder '/' iasi_files(i_files).name],varNames{5});

    CO{i_files} = ncread([folder '/' iasi_files(i_files).name],varNames{6});

    T{i_files} = ncread([folder '/' iasi_files(i_files).name],varNames{7});

    CH4{i_files} = ncread([folder '/' iasi_files(i_files).name],varNames{8});

    HNO3{i_files} = ncread([folder '/' iasi_files(i_files).name],varNames{9});

    N2O{i_files} = ncread([folder '/' iasi_files(i_files).name],varNames{10});


    for j_size = 1:length(levs);

            figure(j_size);

            n_var = length(varNames);

            for i_var = 1:n_var;

                data.varNames{i_var} = varName{i_var};

                Y{i_files} = ncread([folder '/' iasi_files(i_files).name],varNames{i_var});

                latlim = [-20 20];

                lonlim = [-40 40];

                axesm('robinson','MapLatLimit',latlim,'MapLonLimit',lonlim,'Frame','on','Grid','on','MeridianLabel','on','ParallelLabel','on');

                hold on

                scatterm(LAT{i_files},LON{i_files},10,varName{i_files}(j_size,:),'filled');

________________________________________________________________
I want create multiple scatter map where granules from each file, variable in each file at the designated levels and longitude and latitude locations are plotted. Please help if possible.

Also another is, am I calling the function correctly? Should I have the varNames before the function? How can I read type in the command read_netcdf_f('MAY2', '{O3_MR}') or whatever variable I would like.

Jonathan

Jonathan

Subject: calling function to make multiple scatterm plots

From: dpb

Date: 13 Sep, 2013 00:41:11

Message: 2 of 9

On 9/12/2013 6:30 PM, Jonathan W Smith wrote:
...
>
> function data = read_iasi_netcdf_f(folder, varName)
> varNames ={'Latitude','Longitude','Pressure','O3_MR', ...
                'Skin_Temperature','CO_MR','Temperature', ...
                'CH4_MR','HNO3_MR','N2O_MR'};
> varName = {'LAT','LON','P','ozone','skin_t','CO','T','CH4','HNO3','N2O'};
> iasi_files = dir([folder,'/*.nc']);

     iasi_files = dir(fullfile(folder,'*.nc')); % doc fullfile

> % Variable names inside IASI File
> num_iasi_files = length(iasi_files);
> % Opening each variable in IASI netcdf file
> % LAT{i_files}=ncread([folder '/' iasi_files(i_files).name],varNames{1});
>
> %Data structure
> for i_files = 1:num_iasi_files;
> levs = [47 55 61 70 82 85 91 94];
> % Opening each variable in IASI netcdf file
       fn=fullfile(folder,iasi_files(i_files).name);
> LAT{i_files} =ncread(fn,varNames{1});
> LON{i_files} =ncread(fn,varNames{2});
> P{i_files} =ncread(fn,varNames{3});
> ozone{i_files} =ncread(fn,varNames{4});
> skin_t{i_files}=ncread(fn,varNames{5});

...etc., etc., ...

> for j_size = 1:length(levs);
> figure(j_size);
> n_var = length(varNames);
> for i_var = 1:n_var;
> data.varNames{i_var} = varName{i_var};
> Y{i_files}=ncread(fn,varNames{i_var});
> latlim = [-20 20];
> lonlim = [-40 40];
> axesm('robinson','MapLatLimit',latlim, ...
                            'MapLonLimit',lonlim, ...
                            'Frame','on','Grid','on', ...
                            'MeridianLabel','on','ParallelLabel','on');
> hold on
> scatterm(LAT{i_files},LON{i_files},10, ...
                    varName{i_files}(j_size,:),'filled');

> I want create multiple scatter map where granules from each file,
> variable in each file at the designated levels and longitude and
> latitude locations are plotted. Please help if possible.

> Also another is, am I calling the function correctly? Should I have the
> varNames before the function?

Don't have scatterm, etc., so no real help there...


> ... How can I read type in the command
> read_netcdf_f('MAY2', '{O3_MR}') or whatever variable I would like.

Don't follow the question -- you mean to interactively select a variable
name?

Couple of ways; probably most general would be to use the inquire
functions for the file and present a list for the user to select from.

If you know the variables a priori as seemingly do from your above code,
just let them pick from that list instead by either a selection box or
type in the variable name and match the index in your list...

You do _NOT_ want to try to eval an input string--there be dragons.

--

Subject: calling function to make multiple scatterm plots

From: Jonathan W Smith

Date: 13 Sep, 2013 13:55:06

Message: 3 of 9

dpb <none@non.net> wrote in message <l0tmvq$r54$1@speranza.aioe.org>...
> On 9/12/2013 6:30 PM, Jonathan W Smith wrote:
> ...
> >
> > function data = read_iasi_netcdf_f(folder, varName)
> > varNames ={'Latitude','Longitude','Pressure','O3_MR', ...
> 'Skin_Temperature','CO_MR','Temperature', ...
> 'CH4_MR','HNO3_MR','N2O_MR'};
> > varName = {'LAT','LON','P','ozone','skin_t','CO','T','CH4','HNO3','N2O'};
> > iasi_files = dir([folder,'/*.nc']);
>
> iasi_files = dir(fullfile(folder,'*.nc')); % doc fullfile
>
> > % Variable names inside IASI File
> > num_iasi_files = length(iasi_files);
> > % Opening each variable in IASI netcdf file
> > % LAT{i_files}=ncread([folder '/' iasi_files(i_files).name],varNames{1});
> >
> > %Data structure
> > for i_files = 1:num_iasi_files;
> > levs = [47 55 61 70 82 85 91 94];
> > % Opening each variable in IASI netcdf file
> fn=fullfile(folder,iasi_files(i_files).name);
> > LAT{i_files} =ncread(fn,varNames{1});
> > LON{i_files} =ncread(fn,varNames{2});
> > P{i_files} =ncread(fn,varNames{3});
> > ozone{i_files} =ncread(fn,varNames{4});
> > skin_t{i_files}=ncread(fn,varNames{5});
>
> ...etc., etc., ...
>
> > for j_size = 1:length(levs);
> > figure(j_size);
> > n_var = length(varNames);
> > for i_var = 1:n_var;
> > data.varNames{i_var} = varName{i_var};
> > Y{i_files}=ncread(fn,varNames{i_var});
> > latlim = [-20 20];
> > lonlim = [-40 40];
> > axesm('robinson','MapLatLimit',latlim, ...
> 'MapLonLimit',lonlim, ...
> 'Frame','on','Grid','on', ...
> 'MeridianLabel','on','ParallelLabel','on');
> > hold on
> > scatterm(LAT{i_files},LON{i_files},10, ...
> varName{i_files}(j_size,:),'filled');
>
> > I want create multiple scatter map where granules from each file,
> > variable in each file at the designated levels and longitude and
> > latitude locations are plotted. Please help if possible.
>
> > Also another is, am I calling the function correctly? Should I have the
> > varNames before the function?
>
> Don't have scatterm, etc., so no real help there...
>
>
> > ... How can I read type in the command
> > read_netcdf_f('MAY2', '{O3_MR}') or whatever variable I would like.
>
> Don't follow the question -- you mean to interactively select a variable
> name?
>
> Couple of ways; probably most general would be to use the inquire
> functions for the file and present a list for the user to select from.
>
> If you know the variables a priori as seemingly do from your above code,
> just let them pick from that list instead by either a selection box or
> type in the variable name and match the index in your list...
>
> You do _NOT_ want to try to eval an input string--there be dragons.
>
> --

Good morning:
Don't follow the question -- you mean to interactively select a variable name? Clarification: I have a netcdf file with several variables. I want to choose one of those variables to do the scatter map as opposed to a scatter map for all of the variables.

Also its suggested that I could allow the code to pick from the list, how is this done?

I really need some scatterm assistance. Thanks

Subject: calling function to make multiple scatterm plots

From: dpb

Date: 13 Sep, 2013 14:20:23

Message: 4 of 9

On 9/13/2013 8:55 AM, Jonathan W Smith wrote:
> dpb <none@non.net> wrote in message <l0tmvq$r54$1@speranza.aioe.org>...
>> On 9/12/2013 6:30 PM, Jonathan W Smith wrote:
>> ...
>> >
>> > function data = read_iasi_netcdf_f(folder, varName)
>> > varNames ={'Latitude','Longitude','Pressure','O3_MR', ...
>> 'Skin_Temperature','CO_MR','Temperature', ...
>> 'CH4_MR','HNO3_MR','N2O_MR'};
>> > varName =
>> {'LAT','LON','P','ozone','skin_t','CO','T','CH4','HNO3','N2O'};
...

> Also its suggested that I could allow the code to pick from the list,
> how is this done?

 >> [vselect,ok]=listdlg('PromptString','Select a variable to plot:',...
                         'selectionmode','single', ...
                         'liststring',varNames)
vsselect =
      7
 >> varName(vselect)
ans =
     'T'

> I really need some scatterm assistance. Thanks

Sorry, can't help there other than reading the same doc you have; don't
have the necessary toolbox here so no direct info...

--

Subject: calling function to make multiple scatterm plots

From: Steven_Lord

Date: 13 Sep, 2013 15:06:59

Message: 5 of 9



"Jonathan W Smith" <jwsmith9@gmail.com> wrote in message
news:l0v5fq$nv5$1@newscl01ah.mathworks.com...
> dpb <none@non.net> wrote in message <l0tmvq$r54$1@speranza.aioe.org>...
>> On 9/12/2013 6:30 PM, Jonathan W Smith wrote:

*snip*

>> > ... How can I read type in the command
>> > read_netcdf_f('MAY2', '{O3_MR}') or whatever variable I would like.
>>
>> Don't follow the question -- you mean to interactively select a variable
>> name?
>>
>> Couple of ways; probably most general would be to use the inquire
>> functions for the file and present a list for the user to select from.
>>
>> If you know the variables a priori as seemingly do from your above code,
>> just let them pick from that list instead by either a selection box or
>> type in the variable name and match the index in your list...
>>
>> You do _NOT_ want to try to eval an input string--there be dragons.
>>
>> --
>
> Good morning:
> Don't follow the question -- you mean to interactively select a variable
> name? Clarification: I have a netcdf file with several variables. I
> want to choose one of those variables to do the scatter map as opposed to
> a scatter map for all of the variables.

data = load('census.mat');
listOfVariables = fieldnames(data);
whichVariable = listdlg('ListString', listOfVariables, ...
    'PromptString', 'Select one variable to PLOT', ...
    'SelectionMode', 'single');
x = data.(listOfVariables{whichVariable});
plot(x)

If you select cdate, you should see a straight line. If you select pop, you
should something that looks more like a quadratic.

This uses LOAD with an output argument (this is how you should ALWAYS call
LOAD inside a function!) along with dynamic field names. I used LOAD and
PLOT as a simple example; it should work similarly for NCINFO, NCREAD, and
SCATTERM.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: calling function to make multiple scatterm plots

From: Jonathan W Smith

Date: 13 Sep, 2013 15:09:06

Message: 6 of 9

dpb <none@non.net> wrote in message <l0v6vo$eka$1@speranza.aioe.org>...
> On 9/13/2013 8:55 AM, Jonathan W Smith wrote:
> > dpb <none@non.net> wrote in message <l0tmvq$r54$1@speranza.aioe.org>...
> >> On 9/12/2013 6:30 PM, Jonathan W Smith wrote:
> >> ...
> >> >
> >> > function data = read_iasi_netcdf_f(folder, varName)
> >> > varNames ={'Latitude','Longitude','Pressure','O3_MR', ...
> >> 'Skin_Temperature','CO_MR','Temperature', ...
> >> 'CH4_MR','HNO3_MR','N2O_MR'};
> >> > varName =
> >> {'LAT','LON','P','ozone','skin_t','CO','T','CH4','HNO3','N2O'};
> ...
>
> > Also its suggested that I could allow the code to pick from the list,
> > how is this done?
>
> >> [vselect,ok]=listdlg('PromptString','Select a variable to plot:',...
> 'selectionmode','single', ...
> 'liststring',varNames)
> vsselect =
> 7
> >> varName(vselect)
> ans =
> 'T'
>
> > I really need some scatterm assistance. Thanks
>
> Sorry, can't help there other than reading the same doc you have; don't
> have the necessary toolbox here so no direct info...
>
> --
>
I want to be able to feed this into the function. putting the command line [vselect,ok]=listdlg('PromptString','Select a variable to plot:',...
> 'selectionmode','single', ...
> 'liststring',varNames)

before the function will not work in the script. function has to be the first command in this script. Any suggestions?

Thanks

Subject: calling function to make multiple scatterm plots

From: Jonathan W Smith

Date: 13 Sep, 2013 15:21:07

Message: 7 of 9

"Steven_Lord" <slord@mathworks.com> wrote in message <l0v9mj$ir7$1@newscl01ah.mathworks.com>...
>
>
> "Jonathan W Smith" <jwsmith9@gmail.com> wrote in message
> news:l0v5fq$nv5$1@newscl01ah.mathworks.com...
> > dpb <none@non.net> wrote in message <l0tmvq$r54$1@speranza.aioe.org>...
> >> On 9/12/2013 6:30 PM, Jonathan W Smith wrote:
>
> *snip*
>
> >> > ... How can I read type in the command
> >> > read_netcdf_f('MAY2', '{O3_MR}') or whatever variable I would like.
> >>
> >> Don't follow the question -- you mean to interactively select a variable
> >> name?
> >>
> >> Couple of ways; probably most general would be to use the inquire
> >> functions for the file and present a list for the user to select from.
> >>
> >> If you know the variables a priori as seemingly do from your above code,
> >> just let them pick from that list instead by either a selection box or
> >> type in the variable name and match the index in your list...
> >>
> >> You do _NOT_ want to try to eval an input string--there be dragons.
> >>
> >> --
> >
> > Good morning:
> > Don't follow the question -- you mean to interactively select a variable
> > name? Clarification: I have a netcdf file with several variables. I
> > want to choose one of those variables to do the scatter map as opposed to
> > a scatter map for all of the variables.
>
> data = load('census.mat');
> listOfVariables = fieldnames(data);
> whichVariable = listdlg('ListString', listOfVariables, ...
> 'PromptString', 'Select one variable to PLOT', ...
> 'SelectionMode', 'single');
> x = data.(listOfVariables{whichVariable});
> plot(x)
>
> If you select cdate, you should see a straight line. If you select pop, you
> should something that looks more like a quadratic.
>
> This uses LOAD with an output argument (this is how you should ALWAYS call
> LOAD inside a function!) along with dynamic field names. I used LOAD and
> PLOT as a simple example; it should work similarly for NCINFO, NCREAD, and
> SCATTERM.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

OK. Thanks for your response. We replied within 3 minutes of one another.
It does not seem like you use function at all. Is the command line you suggest Steve, go inside that same script with the function ?

Jonathan

Subject: calling function to make multiple scatterm plots

From: Steven_Lord

Date: 13 Sep, 2013 15:51:20

Message: 8 of 9



"Jonathan W Smith" <jwsmith9@gmail.com> wrote in message
news:l0vah3$5qm$1@newscl01ah.mathworks.com...
> "Steven_Lord" <slord@mathworks.com> wrote in message
> <l0v9mj$ir7$1@newscl01ah.mathworks.com>...

*snip*

>>
>> data = load('census.mat');
>> listOfVariables = fieldnames(data);
>> whichVariable = listdlg('ListString', listOfVariables, ...
>> 'PromptString', 'Select one variable to PLOT', ...
>> 'SelectionMode', 'single');
>> x = data.(listOfVariables{whichVariable});
>> plot(x)
>>
>> If you select cdate, you should see a straight line. If you select pop,
>> you should something that looks more like a quadratic.
>>
>> This uses LOAD with an output argument (this is how you should ALWAYS
>> call LOAD inside a function!) along with dynamic field names. I used LOAD
>> and PLOT as a simple example; it should work similarly for NCINFO,
>> NCREAD, and SCATTERM.
>>
>> --
>> Steve Lord
>> slord@mathworks.com
>> To contact Technical Support use the Contact Us link on
>> http://www.mathworks.com
>
> OK. Thanks for your response. We replied within 3 minutes of one another.
> It does not seem like you use function at all. Is the command line you
> suggest Steve, go inside that same script with the function ?

I wrote this as a simple example script just to demonstrate the concept. You
can, of course, wrap those commands inside a function; if you'll notice,
nowhere do I use a variable before I defined it in that example. You'd
probably want to change the hard-coded 'census.mat' into an input argument
of the function but I'll leave that (and the way to read in the data, and
the specific plot you want to generate) for you to customize.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: calling function to make multiple scatterm plots

From: dpb

Date: 13 Sep, 2013 16:51:29

Message: 9 of 9

On 9/13/2013 10:09 AM, Jonathan W Smith wrote:
> dpb <none@non.net> wrote in message <l0v6vo$eka$1@speranza.aioe.org>...
>> On 9/13/2013 8:55 AM, Jonathan W Smith wrote:
>> > dpb <none@non.net> wrote in message <l0tmvq$r54$1@speranza.aioe.org>...
>> >> On 9/12/2013 6:30 PM, Jonathan W Smith wrote:
>> >> ...
>> >> >
>> >> > function data = read_iasi_netcdf_f(folder, varName)
>> >> > varNames ={'Latitude','Longitude','Pressure','O3_MR', ...
>> >> 'Skin_Temperature','CO_MR','Temperature', ...
>> >> 'CH4_MR','HNO3_MR','N2O_MR'};
>> >> > varName =
>> >> {'LAT','LON','P','ozone','skin_t','CO','T','CH4','HNO3','N2O'};
>> ...
>>
>> > Also its suggested that I could allow the code to pick from the list,
>> > how is this done?
>>
>> >> [vselect,ok]=listdlg('PromptString','Select a variable to plot:',...
>> 'selectionmode','single', ...
>> 'liststring',varNames)
>> vsselect =
>> 7
>> >> varName(vselect)
>> ans =
>> 'T'
>>
>> > I really need some scatterm assistance. Thanks
>>
>> Sorry, can't help there other than reading the same doc you have;
>> don't have the necessary toolbox here so no direct info...
>>
>> --
>>
> I want to be able to feed this into the function. putting the command
> line [vselect,ok]=listdlg('PromptString','Select a variable to plot:',...
>> 'selectionmode','single', ...
>> 'liststring',varNames)
>
> before the function will not work in the script. function has to be the
> first command in this script. Any suggestions?

Say What???!!! I've no klew at this point what you mean. "Feed _what_
into the function"?

You said you wanted to be able to select a given variable from a list;
listdlg() lets the user select one and returns the position index needed
to access it--what more do you want/need?

Why is there any reason the "function has to be the first command in
this script"? A script can/needs must be whatever is needed to do the
task at hand.

--

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