Remove quotation marks from a text string

17 次查看(过去 30 天)
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