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!