Effacer les filtres
Effacer les filtres

Remove quotation marks from a text string

16 vues (au cours des 30 derniers jours)
William
William le 8 Avr 2013
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 commentaires
Yao Li
Yao Li le 8 Avr 2013
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 le 8 Avr 2013
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.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 9 Avr 2013
fctName = factors{i, 3}; %notice the {} instead of ()

Plus de réponses (1)

William
William le 9 Avr 2013
Yes, that works, thank you. The bracket choice always trips me up.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by