MATLAB: How can i pad 1024 bits of 1 followed by zeros for already existing binary data(k) if the code is

*****

* data = input('enter the data:','s');
bin = double(data);
display(bin);
n=dec2base(bin,16);
display(n);
k = [dec2bin(bin,8)];
display(k);
len_n = length(n);
display(len_n);
tot_len = len_n*4*2;
len_k = length(k);
display(tot_len);
x = 896-tot_len;
y = x/4;
display(x);
display(y);
if len_-n < 896 padarray = [ones(1,1), zeros(1,x-1)]; display(padarray); end

Best Answer

The question does not clearly explain what you are trying to achieve. It would be clearer if you gave exact examples of the data now, and how you want to change it (eg padding, etc).
It seems that you have some existing numeric vector A and wish to pad this with zeros up to a certain length, then you can try:
A = 1:10;
if numel(A)<1024
A(1024) = 0;
end
OR
A = 1:10;
A = [A,zeros(1,1024-numel(A))]
These will pad the data with zeros up until the index that you provide (e.g. 1024). You might also like to look at padarray .
Note that you use the code ones(1,1), which is simply equivalent to 1. Did you mean to create a vector here, eg ones(1024,1) OR ones(1024-len_n) ?
Also the variable data is a string, which you convert to the character codes using double(data). Is this intentional? Otherwise you can convert the value in the string with num2str, or another string parsing function.