필터 지우기
필터 지우기

Simple data conversion help needed

조회 수: 1 (최근 30일)
Tom
Tom 2014년 2월 18일
댓글: Tom 2014년 2월 18일
Hello,
This is probably very simple.
Can anyone tell me where I'm going wrong when using strcmp:
I have this user input:
former = input('Enter the former','s')
To which the response will be something like: Si4+
I then am trying to seek and utilise instances of that user input, Si4+ like such:
if strcmp(atom_type(i),'former')
form(i,:) = x(i,:);
where atom_type is labelled as a cell containing instance of Si4+ and others.
However this doesn't work. It did however work when instead of 'former' in the strcmp part I explicitly write 'Si4+', so clearly there is some data conversion needed.
I thought
former = cellstr(former)
would work, but alas no.
Can anyone help?
Kind regards,
Tom

채택된 답변

Image Analyst
Image Analyst 2014년 2월 18일
Don't put quotes around former in strcmp(). You might also want to use strcmpi instead. Also, to convert a cell to a character string, use char.
former = char(format); % Convert cell to string.
What is the type of atom_type(i)? Is it a cell? If so, you might need to get the contents of the cell instead of the cell itself by using braces: atom_type{i} or just pass it into char: char(atom_type(i)).
  댓글 수: 2
Image Analyst
Image Analyst 2014년 2월 18일
Tom
Tom 2014년 2월 18일
Thankyou!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by