Hi Ping,
I understand that you want to save images with a filename that includes the current timestamp in the format "yyyy-mm-dd-hhmmss".
To achieve this, we can create a MATLAB function that generates the timestamp, constructs the filename using the timestamp, and saves the image with the generated filename.
Here is an example MATLAB function that demonstrates the suggested workaround:
function saveImageWithTimestamp(image)
% Generate the timestamp in the desired format
dt = datetime('now', 'Format', 'yyyy-MM-dd-HHmmss');
% Convert the datetime object to a string
timestamp = char(dt);
% Create the filename using the timestamp
filename = strcat(timestamp, '.jpg');
% Save the image with the generated filename
imwrite(image, filename);
% Display a message indicating the successful save
fprintf('Image saved as %s\n', filename);
end
To use this function, we should pass the image as an argument when calling “saveImageWithTimestamp”, like this:
image = imread('your_image.jpg');
saveImageWithTimestamp(image);
Please go through the following MATLAB documentation links to know more about the functions used above:
- “imread”: https://www.mathworks.com/help/matlab/ref/imread.html
- “imwrite”: https://www.mathworks.com/help/matlab/ref/imwrite.html
- “datetime”: https://www.mathworks.com/help/matlab/ref/datetime.html
I hope you find this helpful.
Best Regards,
Lokesh