필터 지우기
필터 지우기

reading strings with if statements

조회 수: 1 (최근 30일)
KA
KA 2015년 11월 15일
댓글: KA 2015년 11월 15일
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개)

Geoff Hayes
Geoff Hayes 2015년 11월 15일
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.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by