필터 지우기
필터 지우기

I can't figure out what is wrong with the code. MATLAB

조회 수: 4 (최근 30일)
Kratos
Kratos 2015년 2월 3일
답변: Star Strider 2015년 2월 3일
function y = camelCase(x)
%camelCase Convert name with spaces to camelCase.
y(1) = lower(x(1));
% find the spaces
indall = find(x==' ');
% figure out where consecutive are
% and remove all
consec = diff(indall)==1;
ind = indall;
ind(consec) = [];
y = x;
y(min(ind+1,end)) = upper(y(min(ind+1,end)));
y(indall) = '';
end
This is what I am supposed to get
% out1 = camelCase('This Is a Variable')
% out1 => 'thisIsAVariable'
%
% out2 = camelCase('HERE IS AN EXAMPLE')
% out2 => 'hereIsAnExample'
%
% out3 = camelCase('the CoW jUmPeD over THE mooN')
% out3 => 'theCowJumpedOverTheMoon'
BUT I keep getting something else. ANY HELP!!!!!

채택된 답변

Star Strider
Star Strider 2015년 2월 3일
There may be several ways to accomplish what you want.
Here is one:
S = 'HERE IS AN EXAMPLE';
sp = strfind(S, ' ');
uc = upper(S(sp+1));
SL = lower(S);
SL(sp+1) = uc;
Out = strrep(SL, ' ','')
produces:
Out =
hereIsAnExample

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by