Modify element in a matrix, row vector

조회 수: 2 (최근 30일)
Anh Dao
Anh Dao 2017년 12월 7일
댓글: A.V. Satyanarayana 2021년 9월 2일
I have a row vector and I want the value from 0 to 500 be all zero, how do I do this? Thanks you!

답변 (2개)

James Tursa
James Tursa 2017년 12월 7일
rowvector(rowvector>=0 & rowvector<=500) = 0;
  댓글 수: 1
Guillaume
Guillaume 2017년 12월 7일
Note that the fact that it is a row vector or even a vector is completely irrelevant. The same code would apply for a matrix.

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


Anh Dao
Anh Dao 2017년 12월 7일
To be more detail, I have 3 row vector, which is defined y1, y2 and y3. Their dimension is 1*166500, for y1, I want the first value to be zero, for y2, I want the value from 0 to 500 to be zero and for y3, I want the value from 0 to 501 to be zero, how do I do this? Thanks you!
  댓글 수: 1
A.V. Satyanarayana
A.V. Satyanarayana 2021년 9월 2일
% Separate the rows for simplicity and to use elsewhere as below
y=[1 2 3;4 5 6;7 8 9]
y1=y(1,:)
y2=y(2,:)
y3=y(3,:)
%Just created the matrices of required dimension for demo. You may also
%extract the required files using row extraction operation
y1=(1:166500)
y2=randi(100,1,166500)
y3=randi(100,1,166500)
% In matlab the first element is 1 unlike in maths; so u can change it
% accordingly
y1(1,1)=0
y2(1,1:500)=0
y3(1,1:501)=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