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

조회 수: 2 (최근 30일)
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 CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by