フィルターのクリア

how can i pad 1024 bits of 1 followed by zeros for already existing binary data(k) if my code is?

1 回表示 (過去 30 日間)
* 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
  1 件のコメント
yogya
yogya 2014 年 10 月 12 日
the given message should be converted into binary 8bit data and at the end of the message a 1024 bits i.e, 1 followed by 1023 zeros must be padded. how can i do this in above coading....

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2014 年 10 月 12 日
編集済み: Stephen23 2014 年 10 月 12 日
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.
  2 件のコメント
yogya
yogya 2014 年 10 月 12 日
thank you for helping me. but when i try to run this command in my coad it showing error as ??? Error using ==> horzcat CAT arguments dimensions are not consistent.
Error in ==> prog at 24
C = [k, zeros(1,1024-numel(k))];
what does it mean , how can i correct it
and as i need the binary values of the message i have used double(data) insted of num2str...
Stephen23
Stephen23 2014 年 10 月 30 日
This is because the variable k is not a horizontal vector, unlike the example I gave. You have to use the dimensions of k as inputs to the zeros function. If k is a matrix, one possibility would be (untested):
S = size(k);
C = [k, zeros(S(1),1024-S(2))];

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by