Bowecho
Bowecho

Reputation: 909

How can I eliminate the Matlab error: "converstion to double from struct is not possible"?

I am trying to read multiple images in order to generate a movie in Matlab. So, I use this code:

M = zeros(1,10); 

for i = 1:10 
    images = sprintf('img%d.jpg',i);
    ImageData = imread(images); 
    M(i) = im2frame(ImageData); 
end 

movie(M)

movie2avi(M,'sonar.avi','compression','None','fps',6,'quality',100) 

But I get the following error:

"The following error occurred converting from struct to double:

Error using double

Conversion to double from struct is not possible.

Error in open83B_edited_2 (line 295)

M(i) = im2frame(ImageData);"    

Upvotes: 2

Views: 5251

Answers (1)

Bentoy13
Bentoy13

Reputation: 4966

As written, M is an array of double, so you cannot assign a structure (the result of im2frame) to a double.

It seems that you should not try to allocate the frame stack M; you don't even need to declare M, this variable will be automatically created and the struct array will expand each iteration. Delete the first line and it will works fine.

Upvotes: 2

Related Questions