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 ExchangeLoops 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