2

I have a 1000x1 array, in which i would like it to divide into equal parts based on a lambda value lam_packet, and then in each part i would replace 0 0 0 0 with radom binary values , but whenver i call this function i get an error

??? Error using ==> bsxfun
Non-singleton dimensions of the two input arrays must match each other.

Error in ==> imputation at 11
idx = bsxfun(@plus, idx', (0:3));

please any help would be very much appreciated.

function [ xxx ] = imputation(x,lam_packet,noframes)
x1=x(:,1:-1:1).';
for i=1:lam_packet:noframes
%# starting locations of four-consecutive zeros
idx= strfind(x1(i), [0 0 0 0]);

%# random binary numbers (rows) used to replace the consecutive zeros
n = dec2bin(randi([0 8],[numel(idx) 1]),4) - '0';

%# linear indices corresponding to the consecutive-zeros
idx = bsxfun(@plus, idx', (0:3));

%'# replace the 4-zeros
xx = x1;
xx(idx(:)) = n(:);
end
xxx = xx(1:-1:1,:).';

end
enter code here
Shai
  • 111,146
  • 38
  • 238
  • 371
Spaniard89
  • 2,359
  • 4
  • 34
  • 55

1 Answers1

0

idx is the result of the "strfind" call, which returns the locations of all the [0 0 0 0] strings. Thus, it is an arbitrary sized array, the size of the array depending on the contents of "x1". Thus, it is probably not length 4. Since the other input to bsxfun is length 4, you get the error.

Jim Clay
  • 963
  • 9
  • 24
  • thank you very much for replying, but how could i solve this?? – Spaniard89 Nov 25 '11 at 15:34
  • @Kishore Once you have the [0 0 0 0] locations and a random sequence to replace them with, I would simply do something like "for i=1:length(idx) x1(idx(i):idx(i)+3) = randomSequence; end" – Jim Clay Nov 25 '11 at 15:49
  • Sorry jim clay i didn't understand what you meant?could you please change the part in the code i have provided above! Thank you very much in advance!! – Spaniard89 Nov 25 '11 at 16:00
  • @Kishore There are two problems with doing that. 1) I don't totally understand what it is you're trying to do. 2) Given what I think you are trying to do, I wouldn't have written the code the way you did, so I would rewrite it. I don't have the time to rewrite it. – Jim Clay Nov 25 '11 at 16:47
  • @Kishore It may help to understand the code I did in the comment if I explain that the code should be on three separate lines- the for loop should be on one line, the x1(idx ... line should be on the second line, and the "end" should be on the third line. – Jim Clay Nov 25 '11 at 16:49