How can we represent the day and some parameters of a month - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How can we represent the day and some parameters of a month

eng_subeng_sub Posts: 3Member
Hello,

Could you please help me for this matter?

I have 3 matrices, P (Power), T (Temperature) and H (Humidity)

every matrix has 31 columns (days) and there are 24 rows for every column

which are the data for the March of year 2000, i.e.

for example, the matrix P has 31 columns where every column represents

a day data for Power through 24 hours and the same idea is for T and H

I tried to write a MATLAB program that accomplish my goal but

It gave me errors.

My aim is:

In the MATLAB command window, the program should ask the user the following phrase:

Please enter the day number of March, 2000 from 1 to 31:

And I know it is as follows:

Name=input (Please enter the day number of March, 2000 from 1 to 31:)

Then, when, for example, number 5 is entered, the result shown is a matrix containing the following:

1st column: The day name or it can be represented by numbers

2nd column: simple numbers from 1 to 24 representing the hours for that day

3rd column: the 24 points of P of that day extracted from the original P (the column number 5 of the original P)

4th column: the 24 points of T of that day extracted from the original T (the column number 5 of the original T)

5th column: the 24 points of H of that day extracted from the original H (the column number 5 of the original H)

Then, plotting this extracted P

Any help will be highly appreciated,

Regards



Comments

  • jjasso5jjasso5 Posts: 41Member
    Columns in matrices must have the same number of rows.
    You cannot have a matrix with 1 row for column 1, and
    24 rows for columns 2 to 5.

    You can do that with a cell-array, but they're harder
    to work with.

    This approach is simpler:

    % use your data instead of these matrices
    P = rand(24,31);
    T = rand(24,31);
    H = rand(24,31);

    % here's the important code
    d = input('Please enter the day of March/00 (1-31): ')
    h = [1 : 24]';
    m = [h P(:,d) T(:,d) H(:,d)]
    plot(h, P(:,d))
  • eng_subeng_sub Posts: 3Member
    Thanks for this help

    But how about the column of the day name ( or symbol )

    assume the first day of this month is saturday, it can be represented

    by ( 1 ) and sunday: ( 2 ) ......friday:( 7 )




    Do we need to follow the same method if we want to make a wider

    analysis, for example, letting the program asks the user

    to enter the month number from 1 to 12 ,and after pressing

    the month number

    he asks about the day number and proceed as above?


    thanks

    best regards
  • jjasso5jjasso5 Posts: 41Member
    Learn to use function datestr (type 'help datestr' on your command
    window)

    These two lines

    mdy = ['Mar/3/2000'];
    [datestr(mdy, 8)]

    will display
    Fri

    -----------------------------------
    These two lines

    mdy = ['Mar/3/2000'];
    [datestr(mdy, 8) ' ' mdy]

    will display
    Fri Mar/3/2000

    -----------------------------------

    So, change the final code to this:

    % here's the important code
    d = input('Please enter the day of March/00 (1-31): ');
    mdy = ['Mar/' num2str(d) '/2000'];
    [datestr(mdy, 8) ' ' mdy]
    h = [1 : 24]';
    m = [h P(:,d) T(:,d) H(:,d)]
    plot(h, P(:,d))


    As I mentioned before, you don't get one column with one row.
    First, display the date; later, the four columns with 24 rows each.





  • eng_subeng_sub Posts: 3Member

    Thanks for your cooperation and sorry for disturbing you..


    Unfortunately, the program gave me this error:

    ??? Error using ==> datestr
    Cannot convert input into specified date string.
    DATENUM failed.
    Failed to parse date string.
    Attempted to access amtok(2); index out of bounds because numel(amtok)=1.


    regards
Sign In or Register to comment.