remove zero padding for binary vector and string
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Voss
am 20 Dez. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Signal Generation, Analysis, and Preprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!