# How do I fill a matrix with values of an one array based on another array?

조회 수: 1 (최근 30일)
Maraya Biervliet 2020년 7월 1일
Hi,
I have a 1x5001 array Rr which contains radial distances from a pointsource. I also have an 5001x 1 array Wzr which is the weight vs. radial distance. Also there is a constant dr.
Now I need to make a 2D matrix (5000 x 5000) which is Wzr2D(a,b) = Wzr (Rr(a,b)/dr)
For example if Rr(1,2) = 10 and dr = 2 then I need the value of Wzr(5) to be placed in the matrix Wzr2D at the position (1,2).
I am a super beginner at MATLAB and I don't ever know where to begin to link all this together.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
It shouldn't take much time to work through that page. Indexing is necessary to know if you're using Matlab and it's a very basic tool.

댓글을 달려면 로그인하십시오.

### 답변 (1개)

If I understood correctly, try this:

```Wzr2D(1,:) = Wzr(Rr(1:5000) / dr)
```

This should work if you can guarantee that all values of Rr/dr are valid indices of Wzr, that is, integers between 1 and 5001

##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
I'm not sure why you want to dispose the last element of your data though, nor what's the extra dimention of Wzr2D for

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by