remove zero padding for binary vector and string
7 ビュー (過去 30 日間)
古いコメントを表示
case 1
a=[1 0 0 1 0 1 1 1 1 1 0 0 1 0 1 0 0 1 0 0 0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0];
d=[1 0 1 0 1 0 1 1 0 0 1 1 0 1 1 1 0 1 1 0 1 0 0 1 0 0 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 1 1 1 1]
q=zeros(1,length(d)-length(a))
w=[a q]
case 2
x = input('x: ','s')
y = input('y: ','s')
nx = length(x)
ny = length(y)
if ny > nx
sprintf(sprintf('%%0%is',ny),x)
elseif nx > ny
sprintf(sprintf('%%0%is',nx),y)
else
display('nx=ny')
end
how to remove zero padding for case 1 and case 2? can anyone help me?
0 件のコメント
回答 (1 件)
Voss
2023 年 12 月 20 日
case 1
a=[1 0 0 1 0 1 1 1 1 1 0 0 1 0 1 0 0 1 0 0 0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0];
d=[1 0 1 0 1 0 1 1 0 0 1 1 0 1 1 1 0 1 1 0 1 0 0 1 0 0 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 1 1 1 1];
w=a;
case 2
Possibly this:
x = input('x: ','s')
y = input('y: ','s')
nx = length(x)
ny = length(y)
if ny > nx
sprintf('%*s',ny,x)
elseif nx > ny
sprintf('%*s',nx,y)
else
display('nx=ny')
end
Or possibly this:
x = input('x: ','s')
y = input('y: ','s')
nx = length(x)
ny = length(y)
if ny > nx
sprintf('%s',x)
elseif nx > ny
sprintf('%s',y)
else
display('nx=ny')
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Signal Generation, Analysis, and Preprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!