How can i change the "name" of my picture when using the imread('name') function?

8 ビュー (過去 30 日間)
What i want to do is have a loop go through and read the name of every picture i have.
What i can't do is change the 'Name'(of the image) in a function like imread('Name') in the following way. (i believe this is because 'Name' is interpreted as a string)
(also the names of my pictures are integer values already)
for i = 1:n
image = imread('NameOfMyImage');
end % code
  1 件のコメント
Stephen23 2015 年 4 月 2 日
編集済み: Stephen23 2015 年 4 月 2 日



Christiaan 2015 年 4 月 2 日
Dear Ely,
To import an image in MATLAB, you have to specify the extension. (i.e. Name.jpg)
In the code below you find a method how you can dynamically load multiple images in MATLAB with a for loop and give them the correct name. In the example is assumed you have JPG images. However you can extend the example yourself to also load PNG images. (for this example you need three images: Name_1.jpg, Name_2.jpg and Name_3.jpg.
clc;clear;close all;
% this is how you create a string in a for loop
for i = 1:3
name_of_the_file = sprintf('Name_%d.jpg', i)
name_of_the_image = sprintf('Name_%d', i)
image = imread(name_of_the_file);
clear image name_of_the_file name_of_the_image i
Good luck! Christiaan

その他の回答 (0 件)



Community Treasure Hunt

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

Start Hunting!

Translated by