How to put values in matrix based on some condition?

조회 수: 3 (최근 30일)
Rasif Ajwad
Rasif Ajwad 2015년 10월 28일
댓글: Rob Campbell 2015년 10월 28일
Hi,
I have a matrix. I want put 0 value in (2,1), (3,1), (4,1), (5,1) ... (n,1) positions. ***Not in (1,1) position.
Is it possible to do it with a single line of code?
Thanks.

채택된 답변

Rob Campbell
Rob Campbell 2015년 10월 28일
>> r=rand(5);
>> r(2:end,1)=0
r =
0.0596 0.0967 0.6596 0.4538 0.1734
0 0.8181 0.5186 0.4324 0.3909
0 0.8175 0.9730 0.8253 0.8314
0 0.7224 0.6490 0.0835 0.8034
0 0.1499 0.8003 0.1332 0.0605
Is that what you need?
  댓글 수: 2
Rasif Ajwad
Rasif Ajwad 2015년 10월 28일
Yeah, thanks. I got the idea. So now, f I want 0 value in (1,1), (5,1), (9,1) etc. positions I just need to write:
r(1:4:end,1)=0
Right?
Rob Campbell
Rob Campbell 2015년 10월 28일
Yep!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by