Use switch for a matrix row
11 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I want to use switch to create a video with videowriter. I have written this piece of code. I want to use the cases to judge the rows which picture it has to insert as a frame, but if I do this, I get the following error:
SWITCH expression must be a scalar or character vector constant.
Error in FootSwitchDataAnalysis (line 120) switch M3(i,:);
How can I fix this?
M3 = zeros(6,4)
for i=1:size(M3,i);
switch M3(i,:)
case M3(i,:) == [0 0 0 0]
Frame = imread('FootVis.png')
case M3(i,:) == [1 1 1 1]
Frame = imread('FootVis3.png')
end
frame2insert = im2frame(Frame)
writeVideo(v,frame2insert)
0 件のコメント
回答 (1 件)
Birdman
2018 年 4 月 26 日
編集済み: Birdman
2018 年 4 月 26 日
Use if instead switch:
if all(M3(i,:)==[0 0 0 0])
if all(M3(i,:)==[1 1 1 1])
2 件のコメント
Birdman
2018 年 4 月 26 日
But as said in the error
SWITCH expression must be a scalar or character vector constant.
Therefore you need to take into consideration what I said. Use ismember for comparison of numeric arrays or use all with the structure that I said.
if all(M3(i,:)==[0 0 0 0])
or
if prod(ismember(M3(i,:),[0 0 0 0]))
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!