Subscripted assignment dimension mismatch.

1 回表示 (過去 30 日間)
Nour Mawla
Nour Mawla 2015 年 4 月 18 日
コメント済み: Nour Mawla 2015 年 4 月 18 日
good after noon everyone! please help me in this error i need to create a data base to 500 images all of dimension 100x100 and to compare it with another image of the same dimension when creating the database i use
for i=1:500
dataBase(i,:)=['Images/Database/' int2str(i) '.jpg '];
end
save Database
however the code only reads the first 9 images then display the following error * *
Subscripted assignment dimension mismatch.
Error in DB(line 3)
dataBase(i,:)=['Images/Database/' int2str(i) '.jpg '];* *
and the dataBase appears as 9x22 double i=10
please help me thanks

採用された回答

Image Analyst
Image Analyst 2015 年 4 月 18 日
You need to have a cell array, unless you use sprintf('%3.3d') to create your string in which case you can use a character array like you're trying.
dataBase(i) = {sprintf('Images/Database/%d.jpg', i)};
That creates a cell - the i'th cell of database - where the contents of the cell are the filename string. Please read this: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
Like I said you might be able to create a character array if you use 3.3d to ensure that all strings are the same length and thus the character array will be perfectly rectangular.
dataBase(i, :) = sprintf('Images/Database/%3.3d.jpg', i);
I did not test the above line of code. Also, to use it you'd definitely need to preallocate an array with the right number of columns
database = zeros(500, 23);

その他の回答 (2 件)

Matt J
Matt J 2015 年 4 月 18 日
編集済み: Matt J 2015 年 4 月 18 日
Since your strings have different lengths, you should hold them in a cell array,
for i=1:500
dataBase{i}=['Images/Database/' int2str(i) '.jpg '];
end
To hold them as a char array, you would have to pad the strings with spaces to make them of equal length. The char() command can do this, but it is questionable how essential this is for you.
  4 件のコメント
Matt J
Matt J 2015 年 4 月 18 日
Once you have the cell array, you can convert as follows,
dataBase=char(dataBase)
Nour Mawla
Nour Mawla 2015 年 4 月 18 日
thanks Mr. Matt J I will test it now, really really thanks for your help and your time i appreciate it so much....love you <3

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


Nour Mawla
Nour Mawla 2015 年 4 月 18 日
Ms. Image Analyst Thank you Thank you THANK YOU <3 <3 It worked like magic really thanks I LOVE YOU SOOOO MUCH :*

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by