replacing values from one array to another in different sizes

4 ビュー (過去 30 日間)
Morten Jørgensen
Morten Jørgensen 2019 年 3 月 27 日
コメント済み: Morten Jørgensen 2019 年 3 月 27 日
Hi
I am really struggeling with solving this problem.
% I have an array called mBall 15001x4 with only zeroes in fourth column
mBall(1:15001,4) = 0;
-3.42 -24.55 5.19 0
-3.01 -24.59 5.66 0
-2.59 -24.64 6.11 0
-2.19 -24.69 6.53 0
-1.78 -24.73 6.91 0
-1.38 -24.79 7.28 0
-0.98 -24.84 7.63 0
% this is what an exsample of what my mBall looks like
% I have an array c that consist of 3786x2, below is an exsample of c
% The fist column in c, should be corresponding to the row nr in mBall
c =
2 1
3 1
4 2
5 3
7 3
% I'm trying to replace the values in fourth column of mBall, with the values in second column of c
% mBall should look like this afterwards
mball =
-3.42 -24.55 5.19 0
-3.01 -24.59 5.66 1
-2.59 -24.64 6.11 1
-2.19 -24.69 6.53 2
-1.78 -24.73 6.91 3
-1.38 -24.79 7.28 0
-0.98 -24.84 7.63 3

採用された回答

Image Analyst
Image Analyst 2019 年 3 月 27 日
Try
rowsToReplace = c(:, 1);
mBall(rowsToReplace, 4) = c(:, 2);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by