- “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
matlab如何利用函数自动保存图像并以时间命名yyyy-mm-dd-hhmmss?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
matlab如何利用函数自动保存图像并以时间命名yyyy-mm-dd-hhmmss?
以保存时的时间为名称,例如2021-12-29-100530
0 commentaires
Réponses (1)
Lokesh
le 11 Oct 2023
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:
I hope you find this helpful.
Best Regards,
Lokesh
0 commentaires
Voir également
Catégories
En savoir plus sur Image display and manipulation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!