필터 지우기
필터 지우기

Remove quotation marks from a text string

조회 수: 10 (최근 30일)
William
William 2013년 4월 8일
I have an Excel table that I load into Matlab, containing a lookup string, and the name of the cell array (within Matlab) wherein I will find the string. For instance, a row in this table may be:
MSWXAUL saaDataTitles
MSWXAUL will be the contents of one of the cells in saaDataTitles.
What I want to do is determine the location of the lookup string within the cell array. I'm using find(strcmp( )) to do so, which seems to work fine. My issue is that when I load the Excel table, the entries acquire quotation marks, thus:
'MSWXAUL' 'saaDataTitles'
That's fine for the lookup value; but it means that Matlab doesn't recognise the array name as an array name rather than a text string. It's my understanding that it needs to read saaDataTitles rather than 'saaDataTitles'.
How can I get this to work? I'm open to any approach - trimming the first and last characters to get rid of the quotation marks, extracting anything that isn't a quotation mark, changing the nature of the string, loading it via a different method in the first place, whatever else might work - but can't figure out how to do it.
  댓글 수: 2
Yao Li
Yao Li 2013년 4월 8일
Your purpose is to find out the header name of the column or row. Am I right? So I think it's OK if Matlab returns an array rather than a text string. Why you just need a text string without quotation marks?
William
William 2013년 4월 8일
Not exactly right, no. I have the name of the column header; I want to find its location within a cell array.
To flesh this out further, here's the code that attempts to make use of the inputs:
for i = 1:length(fctTitle)
fctLocation = factors(i, 2);
fctName = factors(i, 3);
fctNo = find(strcmp(fctName, fctLocation));
end
Continuing the original example, fctLocation would return 'saaDataTitles' and fctName would return 'fctNo' (with the quotation marks, in each case). That's fine for fctName, which is the text string being searched for. However, (I think) I need fctLocation to return a reference rather than a text string, and the quotations are getting in the way of that.

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

채택된 답변

Walter Roberson
Walter Roberson 2013년 4월 9일
fctName = factors{i, 3}; %notice the {} instead of ()

추가 답변 (1개)

William
William 2013년 4월 9일
Yes, that works, thank you. The bracket choice always trips me up.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by