I have a table test that says
month
--
'January'
'JANUARY'
I want to replace 'JANUARY' by 'January':
month
--
'January'
'January'
I tried strcmp but I got an error message "conversion to cell from char is not possible." Please advise.

 채택된 답변

Mara
Mara 2020년 6월 18일
편집: Mara 2020년 6월 18일

0 개 추천

test = table();
test.month = 'JANUARY';
test.month = lower(test.month); %writes it in lower case letters
or you can as well just replace it by your desired input
test.month = 'january';
P.S. You do not have a string but a character (char)

댓글 수: 5

alpedhuez
alpedhuez 2020년 6월 18일
편집: alpedhuez 2020년 6월 18일
IQ=IQ+1;
Is it possible to have 'January' that is the first letter capital but the followins are lower?
Mara
Mara 2020년 6월 18일
you can index into your character like a normal array: test.month(2:end) = lower(test.month(2:end)), so that the first character is not changed
alpedhuez
alpedhuez 2020년 6월 18일
편집: alpedhuez 2020년 6월 18일
It only works for the first row.
Mara
Mara 2020년 6월 18일
편집: Mara 2020년 6월 18일
then you have to specify that you want every row:
test.month(:,2:end) = lower(test.month(:,2:end));
alpedhuez
alpedhuez 2020년 6월 18일
편집: alpedhuez 2020년 6월 18일
IQ=IQ+1; % Thank you.

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

추가 답변 (1개)

Deepak Gupta
Deepak Gupta 2020년 6월 18일

0 개 추천

I am providing a solution, i suspect it's not the ideal solution but it should work.
test = table();
test.month{1} = 'JANUARY';
test.month{2} = 'January';
for index = 1:length(test.month)
if(test.month{index}=='JANUARY')
test.month{index} = 'January';
end
end

댓글 수: 1

It depends on whether you have a cell array containing characters or characters solely. From the previous error message that occured ("conversion to cell from char is not possible.") , I concluded, that it is stored as characters only. In which case it does not let you index with curly braces
this worked for me:
test = table();
test.month = {'JANUARY'; 'FEBRUARY'; 'MARCH'}; %cell
test.month = char(test.month); %conversion to character array
test.month(:,2:8) = lower(test.month(:,2:8)); %indexing with normal braces

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

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

릴리스

R2020a

태그

질문:

2020년 6월 18일

편집:

2020년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by