Effacer les filtres
Effacer les filtres

reading strings with if statements

1 vue (au cours des 30 derniers jours)
KA
KA le 15 Nov 2015
Commenté : KA le 15 Nov 2015
Hi I have the following:
clc
clear
matrix=[1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16];
letter='da';
if letter(1)=='a'
pos1=matrix(1,1)+matrix(1,3);
elseif letter(1)=='b'
pos1=matrix(2,1)+matrix(2,3);
elseif letter(1)=='c'
pos1=matrix(3,1)+matrix(3,3);
elseif letter(1)=='d'
pos1=matrix(4,1)+matrix(4,3);
if letter(2)=='a'
pos2=matrix(1,1)+matrix(1,3);
elseif letter(2)=='b'
pos2=matrix(2,1)+matrix(2,3);
elseif letter(2)=='c'
pos2=matrix(3,1)+matrix(3,3);
elseif letter(2)=='d'
pos2=matrix(4,1)+matrix(4,3);
end
disp(matrix)
disp(pos1)
disp(pos2)
This cannot be evaluated by MATLAB any clues?
  1 commentaire
KA
KA le 15 Nov 2015
Thank you Geoff.

Connectez-vous pour commenter.

Réponses (1)

Geoff Hayes
Geoff Hayes le 15 Nov 2015
Antoni - you are missing an end after the third elseif just prior to the next if
elseif letter(1)=='d'
pos1=matrix(4,1)+matrix(4,3);
end %<-----missing end
if letter(2)=='a'
You need to end the first if and elseif block before you begin a new one.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by