remove zero padding for binary vector and string
7 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Voss
on 20 Dec 2023
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 Comments
See Also
Categories
Find more on Signal Generation, Analysis, and Preprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!