reading multiple images - strcat

8 ビュー (過去 30 日間)
Raviteja
Raviteja 2011 年 9 月 20 日
コメント済み: elz tomz 2018 年 7 月 9 日
In a folder I have 50 images of 5 subjects 10 each. (all are .jpg format) I named them as
sub1 (1)
sub1 (2)
...
...
sub1 (10)
sub2 (1)
sub2 (2)
...
...
...
...
..
sub5 (10)
I want to read them in matlab.
I have written following code in matlab
for i=1:5
for j=1:10
name=strcat('sub',int2str(i), ,'(',int2str(j),')','.jpg');
I=imread(name);
% some code
% some code
end
end
in the above code problem is with strcat can you please correct the above code. and can you give any alternative way to read all these images from the folder ?
  3 件のコメント
Raviteja
Raviteja 2011 年 9 月 20 日
Yes, I want a null character!
Jan
Jan 2011 年 9 月 20 日
@Raviteja: A space is *not* a null character. Does my answer using SPRINTF solve your problem?

サインインしてコメントする。

回答 (2 件)

Jan
Jan 2011 年 9 月 20 日
Unfortuanely STRCAT removes marginal spaces from its inputs:
strcat('a', ' ', 'b')
>> ab
This was necessary when string lists have been implemented as CHAR matrices before CELLs have been invented - if I remember correctly this happend in Matlab 4.1.2. Using the CAT command is not influenced by this "smart" unblanking.
For your problem SPRINTF seems to be more convenient and it is not influenced by spaces:
name = sprintf('sub%d (%d).jpg', i, j);

SHEKHAR YADAV
SHEKHAR YADAV 2015 年 7 月 6 日
for i=1:5 for j=1:10; strcat('d',int2str(i),int2str(j))=a(i,:)-b(j,:)
  3 件のコメント
Thorsten
Thorsten 2015 年 7 月 6 日
We cannot run this snipplet as a and b are missing. Further, I think it would be better if you start a new question with an appropriate title instead of posting an answer to a 4 year old question that contains another question...
elz tomz
elz tomz 2018 年 7 月 9 日
for i=1:50 { A=imread(strcat('your image path\','iMAGE STARTING LETTER',int2str(i),'.bmp')); figure;imshow(A); }
just try it out

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by