Asked by sita
on 22 Nov 2012

Hi, below code i am trying to read matrix elements from an array of elements. i should get 5x3 matrix like

1 2 3

1 2 3

1 2 3

1 2 3

1 2 3

but i am gettting like below

1 2 3

1 2 3

1 2 3

1 2 3

3 3 3

i understand there is some problem with indexing.

Please help me in getting this.

i got some answer saying that to remove f(i,:)=k(x) if i do that f is 1 2 3 it is only 1X3 matrix i need it to be 5X3.

i dont want to use repmat because i have to use this in other context where i can not use.

Thanks,

Sita

n=5; v=3; k=[1 2 3];

for i=1:n

x=0;

for j=1:1:v

x=x+1;

f(:,j)= k(x);

end

f(i,:)=k(x)

end

Answer by vipul utsav
on 22 Nov 2012

Edited by Walter Roberson
on 22 Nov 2012

Accepted Answer

n=5; v=3; k=[1 2 3];

for i=1:n

x=0;

for j=1:v

x=x+1;

f(i,j)= k(x);

end

end

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## José-Luis (view profile)

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/54472-problem-in-matrix-indexing#comment_112716

## Walter Roberson (view profile)

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/54472-problem-in-matrix-indexing#comment_112717

Sign in to comment.