Hi
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
% I'm trying to insert values from c(:,2) in mBall(:,4)
% But only in the rows equal to value in c(:,1)
c =
2 1
3 1
4 2
5 3
7 3
% 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

댓글 수: 7

madhan ravi
madhan ravi 2019년 3월 26일
Please illustrate with a short example.
Morten Jørgensen
Morten Jørgensen 2019년 3월 26일
편집: Morten Jørgensen 2019년 3월 26일
Hi,
% I have an array c that consist of 3786x2
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 my mBall looks like
% I'm trying to insert values from c(:,2) in mBall(:,4)
% But only in the rows equal to value in c(:,1)
c =
2 1
3 1
4 2
5 3
7 3
% mBall should look like this
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
madhan ravi
madhan ravi 2019년 3월 26일
I have no idea why some people make even a simple problem harder to be understood.
Morten Jørgensen
Morten Jørgensen 2019년 3월 26일
편집: Morten Jørgensen 2019년 3월 26일
i'm sorry. i have tried to make it simple? is this okay ?
but how should the code look like then?
madhan ravi
madhan ravi 2019년 3월 26일
편집: madhan ravi 2019년 3월 26일
Rows equal to c(:,1) show us how they are matched. It’s not clear.
Morten Jørgensen
Morten Jørgensen 2019년 3월 26일
yes, how should I then put the value into mBall(:,4)?
previously I have used function find like this
[xlocs, ylocs] = find(0 < output & output < 1);
c = [xlocs, ylocs]
% then i have my array mBall, that i want to change
mBall(1:15001,4) = 0;
% I want to replace the 0 in column 4 of mBall with the numbers in ylocs?
% is this more clear?

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

답변 (1개)

KSSV
KSSV 2019년 3월 26일
편집: KSSV 2019년 3월 26일

0 개 추천

Read about logical indexing.
idx = 0 < output5 & output5 < 1 ;
output = output5(idx);

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

2019년 3월 26일

댓글:

2019년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by