How to store number of images matrix and double values in cell or array?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Lizan
am 16 Sep. 2014
Bearbeitet: Image Analyst
am 16 Sep. 2014
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?
0 Kommentare
Akzeptierte Antwort
David Young
am 16 Sep. 2014
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 Kommentar
Image Analyst
am 16 Sep. 2014
Bearbeitet: Image Analyst
am 16 Sep. 2014
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!