array and logicals; deleting columns

조회 수: 7 (최근 30일)
gmltn1212
gmltn1212 2020년 6월 22일
답변: the cyclist 2020년 6월 22일
Hi I am trying to delete a column of array based on a logical (true, false)
arr = [1 2 3; 4 5 6; 7 8 9];
if the logical is this,
logic = '0 1 0' %this is logical values
I am trying to delete the entire column when its true (logical 1). And the returned value should look like this:
new = [1 3; 4 6; 7 9]
Could you do this by using 'logic'? not arr(:,2)]=[]

채택된 답변

the cyclist
the cyclist 2020년 6월 22일
Here is one way.
arr = [1 2 3;
4 5 6;
7 8 9];
logic = [false true false];
new = arr(:,not(logic))

추가 답변 (0개)

카테고리

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