check without using for loop

hi, I want to check if an element =0 or not, then convert it into binary without use for loop, because I have large size of data can do that? data is array with size m*n
for i=1:m
k2=1;
for j=1:n
if data(i,j)~=0
x = dec2bin(~0,data(i,j), 16);
y = transpose(reshape(x, 4, 4));
y1 = bin2dec(y);
aa(1) = int2aa(y1(1));
aa(2) = int2aa(y1(2));
aa(3) = int2aa(y1(3));
aa(4) = int2aa(y1(4));
aa1=[aa(1) aa(2) aa(3) aa(4)];
aaseq1(i,k2)={aa1};
k2=k2+1;
end
end
end
thanks in advance

2 Comments

This code is not valid: DEC2BIN accepts 2 inputs only.
You can create a small and fast lookup-table locally instead of calling INT2AA 4 times. Pre-allocation is also a very good idea. "aaseq1[i,k2}=aa1"; is faster than "aaseq1(i,k2)={aa1};".
thanks,
but when I used
aaseq1{i,k2}=aa1
and use
dlmwrite('codweb.txt',aaseq1);
I got this error
??? Error using ==> dlmwrite at 112
The input cell array cannot be converted to a matrix.
Error in ==> webproc1 at 24
dlmwrite('codweb.txt',aaseq);

Answers (1)

[m,n]=size(data);
aaseq1 = cell(m,n);
[d,ix] = sort(data,2,'descend');
ix(d==0)=inf;
[i2,i2]=sort(ix,2);
d1 = d(bsxfun(@plus,(i2-1)*m,(1:m)'));
t = d1~=0;
d2 = rem(floor(d1(t)*pow2(-15:0)),2);
d3 = blockproc(d2,[1 4],@(block_struct)block_struct.data*pow2((3:-1:0)'));
aaseq1(t) = cellstr(int2aa(d3));

This question is closed.

Tags

Asked:

on 6 Dec 2011

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!