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

Hello,

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

• 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:

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))
• 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

thanks

best regards
• 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.

• 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