"(from 1 to the last bit of m(i)) "

Here is my shot in the dark

m = uint8([1,2,3,4]);

len = length(m);

m_d = 0.5*ones(1,len);

m_xx = cell(1,len);

for jj = 1 : len

m_xx{jj} = bitget( m(jj), [1:8], 'uint8' );

end

m_xx{1}

m_xx{4}

outputs

ans =

1×8 uint8 row vector

1 0 0 0 0 0 0 0

>> m_xx{4}

ans =

1×8 uint8 row vector

0 0 1 0 0 0 0 0

Comments

- bitget only takes whole numbers (I chose uint8 to keep the output short)
- cannot [not meaningsful to] multiply an integer with 0.5
- I stored the result in a cell array, but there are other alternatives

In reponse to comment

Now I understand your question, I think.

Mehmed Saad have listed problems with your puzzling statement. Your statement

m_xx = a(1:(length(a)*.5));

works because the length(a) is an even number.

Try

a=[1 2 3 4];

b=[3 4 5 6];

c=[1 2 4 5];

m=[a b c];

m = { a, b, c };

len = length( m );

m_xx = cell( 1, len );

for jj = 1 : length( m )

m_xx{jj} = m{jj}( 1 : length(m{jj})*0.5 );

end

and

>> m_xx{:}

ans =

1 2

ans =

3 4

ans =

1 2

Comment

The statement in the for-loop looks a lot like your statement. However, you missed

- that m and m_xx need to be cell arrays and
- the difference between () and {} when using cell arrays.

## 2 Comments

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/524329-how-to-control-the-length-of-indexed-array-element#comment_844624

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/524329-how-to-control-the-length-of-indexed-array-element#comment_844624

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/524329-how-to-control-the-length-of-indexed-array-element#comment_844626

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/524329-how-to-control-the-length-of-indexed-array-element#comment_844626

Sign in to comment.