Each number on telephone keypads, except 0 and 1, corresponds to a set of uppercase letters as shown in this list: 2 ABC, 3 DEF, 4 GHI, 5 JKL, 6 MNO, 7 PQRS, 8 TUV, 9 WXYZ Hence, a phone-number specification can include uppercase letters and digits.

조회 수: 23 (최근 30일)
I can not quite figure out why my code does not perform. I keep getting syntax errors that dont make sense to me. Such as "parse errors"
Capture.PNG
  댓글 수: 3
Star Strider
Star Strider 2019년 1월 3일
Please copy and paste your code from your Editor window to a Comment here.
Pictures of code are like pictures of food — enticing but not nourishing.
Emma Sellers
Emma Sellers 2019년 1월 3일
function [telephone] = dial(up)
characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
numbers = '012345678922233344455566677778889999';
[boolean,coords] = ismember(up,characters);
telephone = sscanf(numbers(coords), '%lu');
for i = 1 : sizeof(up)
if boolean(i) = 0
telephone = [];
end
end
end

댓글을 달려면 로그인하십시오.

답변 (3개)

Neil Sheridan
Neil Sheridan 2019년 1월 3일
Firstly sizeof isn't a function (on my MATLAB setup) so I changed to size. Also, use == to check equality of numbers.
for i = 1 : size(up)
if boolean(i) == 0
telephone = [];
end
end
  댓글 수: 14

댓글을 달려면 로그인하십시오.


Neil Sheridan
Neil Sheridan 2019년 1월 4일
When a character is not found in characters() then coords(i) will be 0. numbers(0) will return an error because there is no zeroth element.

RAMAKANT SHAKYA
RAMAKANT SHAKYA 2019년 2월 7일
function s2=dial(n)
p=[n];
s1='';
tx = ismember(p, ['A':'Z','0':'9']);%only digits and capital letters
tx1=sum(tx);
if length(p)<=16&& p(1,1)~='0'&& tx1==length(p) %finding letters
for c=1:length(p)
if p(c)=='A' || p(c)=='B' || p(c)=='C'
s='2';
elseif p(c)=='D' || p(c)=='E' || p(c)=='F'
s='3';
elseif p(c)=='G' || p(c)=='H' || p(c)=='I'
s='4';
elseif p(c)=='J' || p(c)=='K' || p(c)=='L'
s='5';
elseif p(c)=='M' || p(c)=='N' || p(c)=='O'
s='6';
elseif p(c)=='P' || p(c)=='Q' || p(c)=='R' || p(c)=='S'
s='7';
elseif p(c)=='T' || p(c)=='U' || p(c)=='V'
s='8';
elseif p(c)=='W' || p(c)=='X' || p(c)=='Y' || p(c)=='Z'
s='9';
else
for r=0:9 %finding digit if present
t=num2str(r);
if p(c)==t
s=t;
end
end
end
s1=strcat(s1,s); %adding string
s2=str2num(s1); %change into number
s2=uint64(s2); %changing class
end
else
s2=uint64(0);
end
end

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by