Unable to use structName.?ClassName for VideoWriter class
65 ビュー (過去 30 日間)
古いコメントを表示
I am finding the structName.?ClassName method of arguments validation does not work when trying to validate name-value arguments for the VideoWriter class.
I have a short function:
function myDemo(videoData,fileName,vwOpts)
arguments
videoData
fileName
vwOpts.?VideoWriter
end
disp(vwOpts);
videoObj = VideoWriter(fileName);
% Open video, write, close, etc.
end % MakeVideo
I would expect that calling this function with VideoWriter properties such as FrameRate would result in vwOpts being a struct that contains values passed to the function. However, I am getting the error:
>> myDemo(0:10,"myVideo.avi","FrameRate",20)
Error using myDemo
Too many input arguments.
I validated my approach by attempting to filter for arguments to the Bar() function by mimicking the matlab.graphics.chart.primitive.Bar example shown in the documentation and was successful.
I noticed I get this same error when failing to specify the full name of the Bar class, so looked for other methods of specifying the VideoWriter class, using matlab.audiovideo.VideoWriter as the full class name, with no success.
What am I missing about this approach? Is there a way of locating the full name of the VideoWriter class, or is there some reason I should not expect this example to work?
Thanks!
0 件のコメント
採用された回答
Matt J
2025 年 9 月 19 日 14:37
編集済み: Matt J
2025 年 9 月 21 日 10:33
The .?Classname syntax only works on the class properties with public SetAccess. Unfortunately, the VideoWriter class does not have any such properties. FrameRate is also not the name of a property at all:
mc=?VideoWriter;
pl=mc.PropertyList;
table(string({pl.Name}'), string({pl.SetAccess}'), ...
'Var', {'Property Name','SetAccess'})
3 件のコメント
Matt J
2025 年 9 月 22 日 18:31
編集済み: Matt J
2025 年 9 月 22 日 19:43
I think the best you can do is to let VideoWriter()'s argument validation do the work. You can use a try...catch if for some reason you want myDemo() to customize the error messaging,
function myDemo(videoData,fileName,vwNames,vwVals)
arguments
videoData
fileName
end
arguments (Repeating)
vwNames char
vwVals
end
nv=[vwNames;vwVals];
disp(struct(nv{:}));
try
videoObj = VideoWriter(fileName,nv{:});
catch ME
end
end % MakeVideo
その他の回答 (1 件)
Chuguang Pan
2025 年 9 月 17 日 7:19
I think the options.?ClassName syntax is not supported within arguments block. You should specify each name-value pair individually.
function myDemo(videoData,fileName,vwOpts)
arguments
videoData
fileName
vwOpts.FrameRate
% vwOpts.optionname //list distinct VideoWriter option name
% ...
end
disp(vwOpts);
videoObj = VideoWriter(fileName);
% Open video, write, close, etc.
end % MakeVideo
myDemo(0:10,"myVideo.avi",FrameRate=20)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!