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:
Undefined function or method

Subject: Undefined function or method

From: Ender

Date: 9 Jun, 2011 19:49:04

Message: 1 of 13

I am trying to take data that has a time, and date associated with each data point. I would like to put this data into an array which has "[Pressure, Time, Date]

I have a bunch of data points > 10. However I am starting out with just 2 so that I can get some of the bugs out. However this particular bug does not make much sense to me. I get this error,"Undefined function or method 'Press' for input arguments of type 'double'.
" I am not sure why I am getting this error. My logic seems correct, and I don't think I misspelled anything. However, this error is here. Here is an example of my code:

% Pressure at date and time
    
    % Sample 1
        [y, m, d, h, mn,] = datevec('June 07, 2011 11:53:00 AM');
        date1 = sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h, mn) % Month, Day, Year, Hour, Minute
        Press1 = 6.00e-5; % Torr
    
    % Sample 2
        [y, m, d, h, mn,] = datevec('June 07, 2011 1:45:00 PM');
        date2 = sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h, mn) % Month, Day, Year, Hour, Minute
        Press2 = 2.06e-5; % Torr
 
        
% Store date into an array
    for i = 1:2
% date_6_7_11(i) = [date(i)];
        Press_6_7_11 = [Press(i)];
        i = i+1
    end

--Ender--

Subject: Undefined function or method

From: Steven_Lord

Date: 9 Jun, 2011 19:51:24

Message: 2 of 13



"Ender " <jr147@msstate.edu> wrote in message
news:isr83g$60u$1@newscl01ah.mathworks.com...
> I am trying to take data that has a time, and date associated with each
> data point. I would like to put this data into an array which has
> "[Pressure, Time, Date]
>
> I have a bunch of data points > 10. However I am starting out with just 2
> so that I can get some of the bugs out. However this particular bug does
> not make much sense to me. I get this error,"Undefined function or method
> 'Press' for input arguments of type 'double'.
> " I am not sure why I am getting this error. My logic seems correct, and I
> don't think I misspelled anything. However, this error is here. Here is an
> example of my code:
>
> % Pressure at date and time
> % Sample 1
> [y, m, d, h, mn,] = datevec('June 07, 2011 11:53:00 AM');
> date1 = sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h, mn)
> % Month, Day, Year, Hour, Minute
> Press1 = 6.00e-5; % Torr

Do NOT name your variables like Press1, Press2, etc. See the question about
creating A1, A2, etc. in the newsgroup FAQ for some of the reasons you
should not do this and alternatives.

> % Sample 2
> [y, m, d, h, mn,] = datevec('June 07, 2011 1:45:00 PM');
> date2 = sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h, mn)
> % Month, Day, Year, Hour, Minute
> Press2 = 2.06e-5; % Torr
>
> % Store date into an array
> for i = 1:2
> % date_6_7_11(i) = [date(i)];
> Press_6_7_11 = [Press(i)];

You do not have any function or array named Press, so Press(i) correctly
errors.

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

Subject: Undefined function or method

From: Ender

Date: 9 Jun, 2011 19:59:04

Message: 3 of 13

"Steven_Lord" <slord@mathworks.com> wrote in message <isr87s$6l0$1@newscl01ah.mathworks.com>...
>
>
> "Ender " <jr147@msstate.edu> wrote in message
> news:isr83g$60u$1@newscl01ah.mathworks.com...
> > I am trying to take data that has a time, and date associated with each
> > data point. I would like to put this data into an array which has
> > "[Pressure, Time, Date]
> >
> > I have a bunch of data points > 10. However I am starting out with just 2
> > so that I can get some of the bugs out. However this particular bug does
> > not make much sense to me. I get this error,"Undefined function or method
> > 'Press' for input arguments of type 'double'.
> > " I am not sure why I am getting this error. My logic seems correct, and I
> > don't think I misspelled anything. However, this error is here. Here is an
> > example of my code:
> >
> > % Pressure at date and time
> > % Sample 1
> > [y, m, d, h, mn,] = datevec('June 07, 2011 11:53:00 AM');
> > date1 = sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h, mn)
> > % Month, Day, Year, Hour, Minute
> > Press1 = 6.00e-5; % Torr
>
> Do NOT name your variables like Press1, Press2, etc. See the question about
> creating A1, A2, etc. in the newsgroup FAQ for some of the reasons you
> should not do this and alternatives.
>
> > % Sample 2
> > [y, m, d, h, mn,] = datevec('June 07, 2011 1:45:00 PM');
> > date2 = sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h, mn)
> > % Month, Day, Year, Hour, Minute
> > Press2 = 2.06e-5; % Torr
> >
> > % Store date into an array
> > for i = 1:2
> > % date_6_7_11(i) = [date(i)];
> > Press_6_7_11 = [Press(i)];
>
> You do not have any function or array named Press, so Press(i) correctly
> errors.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Please explain. How have I used the index incorrectly? Instead of using the current array to store all of my Press data should I have first put all of my Press data into an array by itself then create and array with Press and date?

--Ender--

Subject: Undefined function or method

From: Ender

Date: 9 Jun, 2011 20:23:04

Message: 4 of 13

"Ender " <jr147@msstate.edu> wrote in message <isr8m8$82e$1@newscl01ah.mathworks.com>...
> "Steven_Lord" <slord@mathworks.com> wrote in message <isr87s$6l0$1@newscl01ah.mathworks.com>...
> >
> >
> > "Ender " <jr147@msstate.edu> wrote in message
> > news:isr83g$60u$1@newscl01ah.mathworks.com...
> > > I am trying to take data that has a time, and date associated with each
> > > data point. I would like to put this data into an array which has
> > > "[Pressure, Time, Date]
> > >
> > > I have a bunch of data points > 10. However I am starting out with just 2
> > > so that I can get some of the bugs out. However this particular bug does
> > > not make much sense to me. I get this error,"Undefined function or method
> > > 'Press' for input arguments of type 'double'.
> > > " I am not sure why I am getting this error. My logic seems correct, and I
> > > don't think I misspelled anything. However, this error is here. Here is an
> > > example of my code:
> > >
> > > % Pressure at date and time
> > > % Sample 1
> > > [y, m, d, h, mn,] = datevec('June 07, 2011 11:53:00 AM');
> > > date1 = sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h, mn)
> > > % Month, Day, Year, Hour, Minute
> > > Press1 = 6.00e-5; % Torr
> >
> > Do NOT name your variables like Press1, Press2, etc. See the question about
> > creating A1, A2, etc. in the newsgroup FAQ for some of the reasons you
> > should not do this and alternatives.
> >
> > > % Sample 2
> > > [y, m, d, h, mn,] = datevec('June 07, 2011 1:45:00 PM');
> > > date2 = sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h, mn)
> > > % Month, Day, Year, Hour, Minute
> > > Press2 = 2.06e-5; % Torr
> > >
> > > % Store date into an array
> > > for i = 1:2
> > > % date_6_7_11(i) = [date(i)];
> > > Press_6_7_11 = [Press(i)];
> >
> > You do not have any function or array named Press, so Press(i) correctly
> > errors.
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > To contact Technical Support use the Contact Us link on
> > http://www.mathworks.com
>
> Please explain. How have I used the index incorrectly? Instead of using the current array to store all of my Press data should I have first put all of my Press data into an array by itself then create and array with Press and date?
>
> --Ender--

I would like to efficiently put all of my time and date data into an arrary preferrably the same array without having to manually type in each variable (e.g. Press = [Press1;Press2, Press3,etc...]

--Ender--

Subject: Undefined function or method

From: Shawn Bonneau

Date: 9 Jun, 2011 20:50:23

Message: 5 of 13

> I would like to efficiently put all of my time and date data into an
> arrary preferrably the same array without having to manually type in each
> variable (e.g. Press = [Press1;Press2, Press3,etc...]
>
> --Ender--

The command Press(i) does not mean Press1, even when i-1. Press(i) indexes
into the press array (in the case of i=1, it takes the first element of
Press). Since you had not defined Press, this causes an error since you are
trying to access data that doesn't exist. If you want to form Press in the
form of [Press1;Press2, Press3,etc...], you can do so when you create the
variables the first time (which as Steven point out really should have
better names). Instead of saying:

  Press1 = 6.00e-5; % Torr
  Press2 = 2.06e-5; % Torr

use:
Press(1)=6.00e-5; % Torr
Press(2) = 2.06e-5; % Torr


Now if you want that value you can access it from the Press array.

Subject: Undefined function or method

From: Steven_Lord

Date: 9 Jun, 2011 20:54:32

Message: 6 of 13



"Ender " <jr147@msstate.edu> wrote in message
news:isra38$chn$1@newscl01ah.mathworks.com...

*snip*

> I would like to efficiently put all of my time and date data into an
> arrary preferrably the same array without having to manually type in each
> variable (e.g. Press = [Press1;Press2, Press3,etc...]

That's what the FAQ entry to which I directed you discusses.

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

Subject: Undefined function or method

From: Ender

Date: 10 Jun, 2011 16:14:05

Message: 7 of 13

"Steven_Lord" <slord@mathworks.com> wrote in message <isrbu8$hq8$1@newscl01ah.mathworks.com>...
>
>
> "Ender " <jr147@msstate.edu> wrote in message
> news:isra38$chn$1@newscl01ah.mathworks.com...
>
> *snip*
>
> > I would like to efficiently put all of my time and date data into an
> > arrary preferrably the same array without having to manually type in each
> > variable (e.g. Press = [Press1;Press2, Press3,etc...]
>
> That's what the FAQ entry to which I directed you discusses.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


Does MATLAB allow me to do this with strings? I am trying to do the same thing with the date and time, but I also get an error. Here is an example of my code:

    % Sample 1 % does not like date(1)
        [y, m, d, h, mn] = datevec('June 07, 2011 11:53:00 AM');
        date(1)= sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h, mn); % Month, Day, Year, Hour, Minute
        Press(1) = 6.00e-5; % Torr
    
    % Sample 2
        [y, m, d, h, mn,] = datevec('June 07, 2011 1:45:00 PM');
        date(2) = sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h, mn); % Month, Day, Year, Hour, Minute
        Press(2) = 2.06e-5; % Torr

I then thought that maybe MATLAB does not like me putting a command into an array. Therefore I then wrote (not literally):
 date1 = sprintf.....etc..
S(1) = date1;

However MATLAB did not like this either. I would like to efficiently put the date into an array. Then I am going to combine the date/time array with the pressure array to make one array.

--Ender--

Subject: Undefined function or method

From: Steven_Lord

Date: 10 Jun, 2011 17:11:59

Message: 8 of 13



"Ender " <jr147@msstate.edu> wrote in message
news:istfsd$cqd$1@newscl01ah.mathworks.com...
> "Steven_Lord" <slord@mathworks.com> wrote in message
> <isrbu8$hq8$1@newscl01ah.mathworks.com>...
>>
>>
>> "Ender " <jr147@msstate.edu> wrote in message
>> news:isra38$chn$1@newscl01ah.mathworks.com...
>>
>> *snip*
>>
>> > I would like to efficiently put all of my time and date data into an
>> > arrary preferrably the same array without having to manually type in
>> > each variable (e.g. Press = [Press1;Press2, Press3,etc...]
>>
>> That's what the FAQ entry to which I directed you discusses.
>>
>> --
>> Steve Lord
>> slord@mathworks.com
>> To contact Technical Support use the Contact Us link on
>> http://www.mathworks.com
>
>
> Does MATLAB allow me to do this with strings? I am trying to do the same
> thing with the date and time, but I also get an error. Here is an example
> of my code:
>
> % Sample 1 % does not like date(1)
> [y, m, d, h, mn] = datevec('June 07, 2011 11:53:00 AM');
> date(1)= sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h,
> mn); % Month, Day, Year, Hour, Minute

The output of your SPRINTF call is not one element in size; it is a
1-by-<something> char array. You can't fit a 1-by-<something> char array
into a 1-by-1 element in another array unless <something> is 1 (which it
isn't in this case) or that "another array" is a cell array.

date{1} = sprintf(...

> Press(1) = 6.00e-5; % Torr
> % Sample 2
> [y, m, d, h, mn,] = datevec('June 07, 2011 1:45:00 PM');
> date(2) = sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h,
> mn); % Month, Day, Year, Hour, Minute
> Press(2) = 2.06e-5; % Torr
>
> I then thought that maybe MATLAB does not like me putting a command into
> an array. Therefore I then wrote (not literally):
> date1 = sprintf.....etc..
> S(1) = date1;
>
> However MATLAB did not like this either. I would like to efficiently put
> the date into an array. Then I am going to combine the date/time array
> with the pressure array to make one array.

Regular arrays must contain only one type of data; you can't combine char
data with numeric data in the same array without converting char to the
numeric type or vice versa. Cell arrays are slightly different; while each
cell's contents must be homogeneous, you can have one cell with char data
and another with numeric data in the same cell array.

C = {'abc', magic(6)}

For more information about cell arrays, read through this section from the
documentation:

http://www.mathworks.com/help/techdoc/matlab_prog/br04bw6-98.html

Be aware of the differences between indexing with parentheses and indexing
with curly braces; that's the most common stumbling block that users of cell
arrays tend to have in my experience. Basically A(1) extracts the first cell
of the cell array A into a new cell array; A{1} extracts the contents of the
first cell of the cell array A into a new array of the appropriate type.

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

Subject: Undefined function or method

From: Ender

Date: 10 Jun, 2011 20:48:05

Message: 9 of 13

"Steven_Lord" <slord@mathworks.com> wrote in message <istj8u$mrn$1@newscl01ah.mathworks.com>...
>
>
> "Ender " <jr147@msstate.edu> wrote in message
> news:istfsd$cqd$1@newscl01ah.mathworks.com...
> > "Steven_Lord" <slord@mathworks.com> wrote in message
> > <isrbu8$hq8$1@newscl01ah.mathworks.com>...
> >>
> >>
> >> "Ender " <jr147@msstate.edu> wrote in message
> >> news:isra38$chn$1@newscl01ah.mathworks.com...
> >>
> >> *snip*
> >>
> >> > I would like to efficiently put all of my time and date data into an
> >> > arrary preferrably the same array without having to manually type in
> >> > each variable (e.g. Press = [Press1;Press2, Press3,etc...]
> >>
> >> That's what the FAQ entry to which I directed you discusses.
> >>
> >> --
> >> Steve Lord
> >> slord@mathworks.com
> >> To contact Technical Support use the Contact Us link on
> >> http://www.mathworks.com
> >
> >
> > Does MATLAB allow me to do this with strings? I am trying to do the same
> > thing with the date and time, but I also get an error. Here is an example
> > of my code:
> >
> > % Sample 1 % does not like date(1)
> > [y, m, d, h, mn] = datevec('June 07, 2011 11:53:00 AM');
> > date(1)= sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h,
> > mn); % Month, Day, Year, Hour, Minute
>
> The output of your SPRINTF call is not one element in size; it is a
> 1-by-<something> char array. You can't fit a 1-by-<something> char array
> into a 1-by-1 element in another array unless <something> is 1 (which it
> isn't in this case) or that "another array" is a cell array.
>
> date{1} = sprintf(...
>
> > Press(1) = 6.00e-5; % Torr
> > % Sample 2
> > [y, m, d, h, mn,] = datevec('June 07, 2011 1:45:00 PM');
> > date(2) = sprintf('Date: %d/%d/%d Time: %d:%d%f\n', m, d, y, h,
> > mn); % Month, Day, Year, Hour, Minute
> > Press(2) = 2.06e-5; % Torr
> >
> > I then thought that maybe MATLAB does not like me putting a command into
> > an array. Therefore I then wrote (not literally):
> > date1 = sprintf.....etc..
> > S(1) = date1;
> >
> > However MATLAB did not like this either. I would like to efficiently put
> > the date into an array. Then I am going to combine the date/time array
> > with the pressure array to make one array.
>
> Regular arrays must contain only one type of data; you can't combine char
> data with numeric data in the same array without converting char to the
> numeric type or vice versa. Cell arrays are slightly different; while each
> cell's contents must be homogeneous, you can have one cell with char data
> and another with numeric data in the same cell array.
>
> C = {'abc', magic(6)}
>
> For more information about cell arrays, read through this section from the
> documentation:
>
> http://www.mathworks.com/help/techdoc/matlab_prog/br04bw6-98.html
>
> Be aware of the differences between indexing with parentheses and indexing
> with curly braces; that's the most common stumbling block that users of cell
> arrays tend to have in my experience. Basically A(1) extracts the first cell
> of the cell array A into a new cell array; A{1} extracts the contents of the
> first cell of the cell array A into a new array of the appropriate type.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


I am having another difficulty. I am trying to plot pressure vs. the time of day when I took the measurement. However, I cannot get the time of measurement to plot correctly. Here is an example of my code:

 % Sample 1 % does not like date(1)
        [y, m, d, h, mn] = datevec('June 07, 2011 11:53:00 AM');
        date{1,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
        date{1,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
        Press(1) = 6.00e-5; % Torr
    
    % Sample 2
        [y, m, d, h, mn,] = datevec('June 07, 2011 1:45:00 PM');
        date{2,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
        date{2,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
        Press(2) = 2.06e-5; % Torr

% Store date into an array
    for i = 1:2
        Press_6_7_11(i,:) = Press(i);
        date_6_7_11(i,1) = date(i,1);
        date_6_7_11(i,2) = date(i,2);
    end
    
    
  % Convert from string to a number
    str2num('date_6_7_11(:,2)');

    
% Plot the results


    % Plot of Time-history
        plot(double(date_6_7_11(:,2)),Press_6_7_11,'b+');


My problem comes in when I try to plot. If I do try to turn the time into a number I get an error sayin,"Conversion to double from cell is not possible."

If I then add a double to my date array I get an error saying the same thing. Am I making this code more complicated then it needs to be, or is something else the matter?

--Ender--

Subject: Undefined function or method

From: Sadik

Date: 11 Jun, 2011 18:17:02

Message: 10 of 13

Hi Ender,

Do this:

plot(Press_6_7_11)
set(gca,'XTickLabel',date_6_7_11(:,2))

Best.

Subject: Undefined function or method

From: Sadik

Date: 11 Jun, 2011 18:24:04

Message: 11 of 13

Small correction:

plot(Press_6_7_11)
set(gca,'XTick',1:2,'XTickLabel',date_6_7_11(:,2))

So when you use 10 points, you will say:

set(gca,'XTick',1:10,'XTickLabel',date_6_7_11(:,2))

Best.

Subject: Undefined function or method

From: Ender

Date: 13 Jun, 2011 19:03:19

Message: 12 of 13

"Sadik " <sadik.hava@gmail.com> wrote in message <it0bs4$1dp$1@newscl01ah.mathworks.com>...
> Small correction:
>
> plot(Press_6_7_11)
> set(gca,'XTick',1:2,'XTickLabel',date_6_7_11(:,2))
>
> So when you use 10 points, you will say:
>
> set(gca,'XTick',1:10,'XTickLabel',date_6_7_11(:,2))
>
> Best.

Thanks for the help thus far. The advice that you have been giving me has helped.

I am running into another problem. I have tried putting all of the data that I have collected for multiple days into one array. I am having problems because my data arrays are not of the same type. At least that's my guess. I thought that I fixed this when I went from {} to (), but that did not solve the problem.

This poises a problem at the end of my code. At the end of my code, I would like to plot the data together on the same plot however my graph is not showing all of the x values. I had to use seperate arrays, and the data values start at different row values. This poses a problem whenever I plot because the x values for the second data are shown, but not the first. Here is a shorten version of my code:


% Pressure at date and time
    % Date: June 7th, 2011
        % Sample 1
            [y, m, d, h, mn] = datevec('June 07, 2011 11:53:00 AM');
    % date{1,1} = sprintf('Date: %d/%d/%d', m, d, y); % Month, Day, Year,
    % date{1,2} = sprintf('Time: %d:%d%f\n',h,mn); % Hour, Minute
            date{1,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{1,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(1) = 6.00e-5; % Torr
    
        % Sample 2
            [y, m, d, h, mn,] = datevec('June 07, 2011 1:45:00 PM');
            date{2,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{2,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(2) = 2.06e-5; % Torr
        
        % Sample 3
            [y, m, d, h, mn,] = datevec('June 07, 2011 2:23:00 PM');
            date{3,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{3,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(3) = 1.70e-5; % Torr

        % Sample 4
            [y, m, d, h, mn,] = datevec('June 07, 2011 3:10:00 PM');
            date{4,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{4,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(4) = 1.40e-5; % Torr
     
        % Sample 5
            [y, m, d, h, mn,] = datevec('June 07, 2011 4:08:00 PM');
            date{5,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{5,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(5) = 1.13e-5; % Torr
    
        % Sample 6
            [y, m, d, h, mn,] = datevec('June 07, 2011 5:10:00 PM');
            date{6,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{6,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(6) = 1.10e-5; % Torr
        
    % Date: June 8th, 2011
        % Sample 7
            [y, m, d, h, mn] = datevec('June 08, 2011 7:38:00 AM');
            date{7,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{7,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(7) = 4.49e-6; % Torr
    
        % Sample 8
            [y, m, d, h, mn,] = datevec('June 08, 2011 8:42:00 AM');
            date{8,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{8,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(8) = 4.00e-6; % Torr
        
        % Sample 9
            [y, m, d, h, mn,] = datevec('June 08, 2011 9:31:00 AM');
            date{9,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{9,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(9) = 3.83e-6; % Torr

        % Sample 10
            [y, m, d, h, mn,] = datevec('June 08, 2011 10:18:00 AM');
            date{10,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{10,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(10) = 3.45e-6; % Torr
     
        % Sample 11
            [y, m, d, h, mn,] = datevec('June 08, 2011 12:00:00 PM');
            date{11,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{11,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(11) = 3.41e-6; % Torr
    
        % Sample 12
            [y, m, d, h, mn,] = datevec('June 08, 2011 1:00:00 PM');
            date{12,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{12,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(12) = 3.39e-6; % Torr
                        
        % Sample 13
            [y, m, d, h, mn,] = datevec('June 08, 2011 2:00:00 PM');
            date{13,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{13,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(13) = 3.34e-6; % Torr
    
        % Sample 14
            [y, m, d, h, mn,] = datevec('June 08, 2011 3:00:00 PM');
            date{14,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{14,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(14) = 3.00e-6; % Torr
            
        % Sample 15
            [y, m, d, h, mn,] = datevec('June 08, 2011 4:00:00 PM');
            date{15,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
            date{15,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
            Press(15) = 3.29e-6; % Torr

 % Store date into an array
        for i = 1:15
            if i <=6
                Press_6_7_11(i,:) = Press(i);
                date_6_7_11(i,1) = date(i,1);
                date_6_7_11(i,2) = date(i,2);
                
            elseif i>6 && i<=15
                Press_6_8_11(i,:) = Press(i);
                date_6_8_11(i,1) = date(i,1);
                date_6_8_11(i,2) = date(i,2);
end
end
 % Plot the results

        % Plot of Time-history of June 7th, 2011
            plot(Press_6_7_11,'r--')
            set(gca,'XTick',1:6,'XTickLabel',date_6_7_11(:,2))
            
        % Hold graph so that other data can be put on the same graph
            hold on
            
        % Plot of Time-history of June 8th, 2011
            plot(Press_6_8_11,'b--')
            set(gca,'XTick',1:15,'XTickLabel',date_6_8_11(:,2))

If I take the second plot, and use 7:15 instead, MATLAB pushes my x values even further to the right, but if I use 1:15 then MATLAB does not display x values for my first set of data. How can I fix this so that I can put multiple data on one graph

--Ender--

Subject: Undefined function or method

From: Kelly Kearney

Date: 13 Jun, 2011 19:42:02

Message: 13 of 13

"Ender " <jr147@msstate.edu> wrote in message
>
> Thanks for the help thus far. The advice that you have been giving me has helped.
>
> I am running into another problem. I have tried putting all of the data that I have collected for multiple days into one array. I am having problems because my data arrays are not of the same type. At least that's my guess. I thought that I fixed this when I went from {} to (), but that did not solve the problem.
>
> This poises a problem at the end of my code. At the end of my code, I would like to plot the data together on the same plot however my graph is not showing all of the x values. I had to use seperate arrays, and the data values start at different row values. This poses a problem whenever I plot because the x values for the second data are shown, but not the first. Here is a shorten version of my code:
>
>
> % Pressure at date and time
> % Date: June 7th, 2011
> % Sample 1
> [y, m, d, h, mn] = datevec('June 07, 2011 11:53:00 AM');
> % date{1,1} = sprintf('Date: %d/%d/%d', m, d, y); % Month, Day, Year,
> % date{1,2} = sprintf('Time: %d:%d%f\n',h,mn); % Hour, Minute
> date{1,1} = sprintf('%d/%d/%d', m, d, y); % Month, Day, Year,
> date{1,2} = sprintf('%d:%d%f\n',h,mn); % Hour, Minute
> Press(1) = 6.00e-5; % Torr

<snip a lot of repetitive code>

> % Store date into an array
> for i = 1:15
> if i <=6
> Press_6_7_11(i,:) = Press(i);
> date_6_7_11(i,1) = date(i,1);
> date_6_7_11(i,2) = date(i,2);
>
> elseif i>6 && i<=15
> Press_6_8_11(i,:) = Press(i);
> date_6_8_11(i,1) = date(i,1);
> date_6_8_11(i,2) = date(i,2);
> end
> end
> % Plot the results
>
> % Plot of Time-history of June 7th, 2011
> plot(Press_6_7_11,'r--')
> set(gca,'XTick',1:6,'XTickLabel',date_6_7_11(:,2))
>
> % Hold graph so that other data can be put on the same graph
> hold on
>
> % Plot of Time-history of June 8th, 2011
> plot(Press_6_8_11,'b--')
> set(gca,'XTick',1:15,'XTickLabel',date_6_8_11(:,2))
>
> If I take the second plot, and use 7:15 instead, MATLAB pushes my x values even further to the right, but if I use 1:15 then MATLAB does not display x values for my first set of data. How can I fix this so that I can put multiple data on one graph
>
> --Ender--


I think you're making this far more complicated than it needs to be. Matlab has some nice built-in functions for manipulating time data between numeric and string formats (datevec, datestr, and datenum) and for labeling plots that use time data (datetick). Rather than repeating code all over the place, and all those sprintf calls and manual xticklabels, try using those:

dates = {...
    'June 07, 2011 11:53:00 AM'
    'June 07, 2011 1:45:00 PM'
    'June 07, 2011 2:23:00 PM'
    'June 07, 2011 3:10:00 PM'
    'June 07, 2011 4:08:00 PM'
    'June 07, 2011 5:10:00 PM'
    'June 08, 2011 7:38:00 AM'
    'June 08, 2011 8:42:00 AM'
    'June 08, 2011 9:31:00 AM'
    'June 08, 2011 10:18:00 AM'
    'June 08, 2011 12:00:00 PM'
    'June 08, 2011 1:00:00 PM'
    'June 08, 2011 2:00:00 PM'
    'June 08, 2011 3:00:00 PM'
    'June 08, 2011 4:00:00 PM'};

Press = [...
    6.00e-5
    2.06e-5
    1.70e-5
    1.40e-5
    1.13e-5
    1.10e-5
    4.49e-6
    4.00e-6
    3.83e-6
    3.45e-6
    3.41e-6
    3.39e-6
    3.34e-6
    3.00e-6
    3.29e-6];

dn = datenum(dates); % Serial date numbers

% Plot all data...

subplot(2,1,1);
plot(dn, Press, '--b.');
datetick('x', 15);

% ... or plot it with a different color each day

unqday = unique(floor(dn));
linespec = {'--b.', '--r.'}; % add enough for all your days

subplot(2,1,2);
hold on;
for id = 1:length(unqday)
   isday = floor(dn) == unqday(id);
   plot(dn(isday), Press(isday), linespec{id});
end
datetick('x', 6); % This time label with mm/dd

Tags for this Thread

No tags are associated with 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