How do I use numerical and logical indices to get this output?

조회 수: 2 (최근 30일)
Luming Tan
Luming Tan 2021년 2월 24일
댓글: Luming Tan 2021년 2월 25일
Provide Matlab code that generates the following output. Given the vectors:
myArray = [2, 4, -3, 6, 9]
How do I use numerical indices and logical indices to get this:
myArray = [2, 4, 1, 6, 9]

답변 (1개)

per isakson
per isakson 2021년 2월 25일
편집: per isakson 2021년 2월 25일
One out of many ways
%%
myArray = [2, 4, -3, 6, 9];
isneg = myArray < 0;
myArray( isneg ) = 1;

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by