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.

22 次查看(过去 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