IF statement yields no output

Hello, I am trying to assign a new matrix with values according to the inputs of two other matrices, see script below. However, vector Distance is not created at all. Could somebody please help?
Thanks.
clear
close all
clc
Revealeddummyfinal_all = importdata('Revealed_dummy_final.xlsx');
Revealeddummyfinal = Revealeddummyfinal_all.data;
Entrance = Revealeddummyfinal(:,6);
CHOICE = Revealeddummyfinal(:,14);
for i = 1:229
if Entrance(i) == 1
if CHOICE(i) == (511 || 512)
Distance(i) = 30;
elseif CHOICE(i) == (521 || 522)
Distance(i) = 40;
elseif CHOICE(i) == (611 || 612)
Distance(i) = 40;
elseif CHOICE(i) == (621 || 622)
Distance(i) = 50;
elseif CHOICE(i) == (711 || 712)
Distance(i) = 50;
elseif CHOICE(i) == (721 || 722)
Distance(i) = 60;
end
elseif Entrance(i) == 2
if CHOICE(i) == (511 || 512)
Distance(i) = 60;
elseif CHOICE(i) == (521 || 522)
Distance(i) = 50;
elseif CHOICE(i) == (611 || 612)
Distance(i) = 50;
elseif CHOICE(i) == (621 || 622)
Distance(i) = 40;
elseif CHOICE(i) == (711 || 712)
Distance(i) = 40;
elseif CHOICE(i) == (721 || 722)
Distance(i) = 30;
end
end
end

 采纳的回答

Stephen23
Stephen23 2018-3-26
编辑:Stephen23 2018-3-26
Instead of this:
CHOICE(i) == (511 || 512)
you need this:
CHOICE(i)==511 || CHOICE(i)==512
Following the rules for operator precedence what you wrote is equivalent to:
CHOICE(i) == (511 || 512)
CHOICE(i) == True
which is likely to be False unless that value of CHOICE is 1 or True.

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Parallel Computing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by