Skip to content
Snippets Groups Projects
Commit 62ec91a0 authored by Jack Driscoll's avatar Jack Driscoll
Browse files

Upload New File

parent 8e34c3fb
No related branches found
No related tags found
No related merge requests found
filename = "time_data.csv";
numDates = 1000;
% Open the file for writing
fileID = fopen(filename, 'w');
for i = 1:numDates
% Generate a random date and time
% Define the range for the year
minYear = 2000;
maxYear = 2100;
% Generate a random year
year = randi([minYear, maxYear]);
% Generate a random month
month = randi([1, 12]);
% Determine the number of days in the generated month
if month == 2
% Check for leap year
if mod(year, 4) == 0 && (mod(year, 100) ~= 0 || mod(year, 400) == 0)
daysInMonth = 29;
else
daysInMonth = 28;
end
elseif any(month == [4, 6, 9, 11])
daysInMonth = 30;
else
daysInMonth = 31;
end
% Generate a random day within the month
day = randi([1, daysInMonth]);
% Generate a random hour (0 to 23)
hour = randi([0, 23]);
% Generate a random minute (0 to 59)
minute = randi([0, 59]);
% Create a datetime object
randomDateTime = datetime(year, month, day, hour, minute, 0);
% Extract components from the datetime object
dayOfWeekName = getDayName(weekday(randomDateTime));
% Write the date components to the file in vertical format
fprintf(fileID, '%d\n', year);
fprintf(fileID, '%02d\n', month);
fprintf(fileID, '%02d\n', day);
fprintf(fileID, '%s\n', dayOfWeekName);
fprintf(fileID, '%02d\n', hour);
fprintf(fileID, '%02d\n\n', minute);
end
% Close the file
fclose(fileID);
function dayName = getDayName(dt)
% Get the day of the week as a number
dayNum = weekday(dt);
% Define the day names
dayNames = {'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'};
% Get the day name
dayName = dayNames{dayNum};
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment