matlab如何利用​函数自动保存图像并以​时间命名yyyy-m​m-dd-hhmms​s?

7 次查看(过去 30 天)
Ping Chen
Ping Chen 2021-12-29
回答: Lokesh 2023-10-11
matlab如何利用函数自动保存图像并以时间命名yyyy-mm-dd-hhmmss?
以保存时的时间为名称,例如2021-12-29-100530

回答(1 个)

Lokesh
Lokesh 2023-10-11
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

类别

Help CenterFile Exchange 中查找有关 Image display and manipulation 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!