How to store number of images matrix and double values in cell or array?

2 ビュー (過去 30 日間)
Lizan
Lizan 2014 年 9 月 16 日
編集済み: Image Analyst 2014 年 9 月 16 日
I am not to familiar with arrays or cells in MATLAB. I would like to make an array that contains in one cell for image 1, image 2, image 3 etc the following per image;
Image Matrix (Pixel value (n x m size) matrix of image) - M
string value - imageType
double value - pos
double value - exposure
How do I do this?
It should be mentioned I will use the values above (matrix and the values) for calculations like sum and so forth etc.
Also, how do I sort them in decreasing order of pos value so that the others also are sorted accordingly?

採用された回答

David Young
David Young 2014 年 9 月 16 日
Cell arrays could be used, but this looks like an ideal case for a struct array. See this introduction. You might do something like this:
for imageNumber = 1:numberOfImages
<read in or compute the current image and its associated data to the variables
M, imageType, pos and exposure>
imageStruct(imageNumber).imageMatrix = M;
imageStruct(imageNumber).imageType = imageType;
imageStruct(imageNumber).pos = pos;
imageStruct(imageNumber).exposure = exposure;
end
Then to sort, something like this:
[~, sortedIndices] = sort([imageStruct.pos], 2, 'descend');
imageStruct = imageStruct(sortedIndices);
which will keep each image with its associated data in the sorted array.
  1 件のコメント
Image Analyst
Image Analyst 2014 年 9 月 16 日
編集済み: Image Analyst 2014 年 9 月 16 日
I agree that a struct array is better and much simpler to understand. That said, the FAQ has a good discussion of cell arrays that should help you get a good intuitive feeling for them http://matlab.wikia.com/wiki/FAQ#Can_you_program_up_the_algorithm_in_this_article_for_me_and_explain_it_to_me.3F>, but again, I recommend David's approach.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by