Hi all! I have a simple question, but I am new to matlab and having difficulty.
I have a column vector of 18000 or so values which are either 1 or 2, representing conditions of an experiment I am running. I need to create a second column vector with the opposite value: so if the number is a 1 in the first column, it needs to be a 2 in the second column (and vice versa).
So far I have:
if allorient(:,1)==1
allorient(:,2)=2
else
allorient(:,2)=1
end
But obviously this is not working and producing a second column of values with only one value. The statement obviously needs to go through each of the values in the first column and then use this to post the alternative value in the second column.
Thanks in advance if someone could help me :-)

 채택된 답변

Rik
Rik 2018년 4월 26일

0 개 추천

You should use logical indexing, like in the example below, or use a loop.
LogicalIndexing=allorient(:,1)==1;
allorient( LogicalIndexing,2)=2;
allorient(~LogicalIndexing,2)=1;

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2018년 4월 26일

답변:

Rik
2018년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by