Dot name reference on non-scalar structure using Video Reader class

Hi... I am trying to read in a .wmv. I have basically copied the example from the VideoReader class in the help but I get this error when I run the .m:
Dot name reference on non-scalar structure.
Error in VideoReader/read (line 91)
if( ~isempty(obj.NumberOfFrames) )
Error in vidFile (line 22)
mov(i).cdata = read(Test, i);
mov is a 1xNumberOfFrames struct with objects 'cdata' and 'colormap'. The main issue is number frames it reads before this error is thrown varies.
Please help. I have banged my head against the wall enough...

Answers (1)

@Townsend:
I'm afraid you've stumbled upon a bug that persists since R2012a. Matlab sometimes erroneously interprets a scalar structure as being non-scalar when confronted with a getfield operation: S.fieldname
A workaround is to insert an index on the field reference like this: S(1).fieldname
It's ugly but it works. So in your case your code could read: if( ~isempty(obj(1).NumberOfFrames) )

9 Comments

Do you have a link to the bug report? This seems like it could potentially cause a huge amount of code to break.
@Daniel:
Indeed, this bug has a large impact on existing code and I've submitted a Service Request. If they can't resolve I'll file a bug;-)
@Ralph
I have tried adding an index like you suggested but I do not have access to save the "new" read function (from VideoReader class). So I then save it locally and then I get this error.
Error using message/getString
Incorrect number of parameters supplied for 'MATLAB:class:MethodRestricted'. Expected 2 but
found 1.
Error in VideoReader.handleImplException (line 357)
throwAsCaller(MException(implException.identifier, msgObj.getString));
Error in vidFile>read (line 108)
VideoReader.handleImplException(err);
Error in vidFile (line 16)
mov(k).cdata=read(obj,k);
Error in dataFile (line 78)
[nFrames, rFrames, Duration, Format, vWidth, vHeight, hf, mov] = vidFile(vid_file);
I have tried to find out how to by pass this but it is above my coding knowledge and the examples I find don't make sense to me. I guess I am not as familiar with matlab as originally thought.
Thanks for you help in advance.
@Townsend
If you're still coping with this bug send me your script and I'll see what I can do. Which Matlab release are you using, I can't find any recent release with the code you supplied?
Check my website to contact me: www.hummeling.com
@Ralph
I have a very similar issue to Townsend's, and am disappointed to learn it's a MATLAB bug! For some reason the read() function works for the first 40 or so frames of my video, then throws an error after that. I also am not able to edit the MATLAB read() function. I'm using the R2012b release -- any help would be greatly appreciated.
Bryan
Has anybody resolved this issue? I am having the same problem.
Thanks! Flori
You can search for VideoReader bugs here. Click that link, then scroll down.
Having a similar problem in 2012b.. Tried editing as suggested too.. doesn't work... Kindly suggest some solution..

Sign in to comment.

Asked:

on 24 Sep 2012

Commented:

on 19 Mar 2014

Community Treasure Hunt

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

Start Hunting!