How to add cell array elements iteratively?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hassan Ashraf
am 27 Apr. 2019
Kommentiert: Hassan Ashraf
am 27 Apr. 2019
I have a cell array of 36 elements and each element is a image of 25x256 unit8 dimension. I want to add all these elements iteratively. I am able to do so by adding one by one but unable to add them in a loop. I am getting the error shown in below picture.![111.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/216953/111.png)
![111.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/216953/111.png)
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 27 Apr. 2019
Hassan - first, please rename the sum variable since there is a built-in MATLAB function of the same name. If you want to add all of these matrices together (assuming that all are 25x256) then just do
compositeImage = im{1};
for k=2:length(im)
compositeImage = compositeImage + im{k};
end
In your code, you are getting an error because you should be referencing im instead of sum when adding the kth image...since it is im that is the cell array.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!