Working with cells of letters

Hi all,
I have a cell (1 by X) containing various other cells of letters. I would like to create a loop (X is a variable) which "extracts" each cell from the main cell AND converts it to a double. Can this be done?
Having issues achieving this as MATLAB doesn't seem to enjoy working with letters!
Craig
[EDITED, Jan, copied from comment section]
X= {{'AB';'AC';'AE':'AD'},{'ABC';'ACD'},{'ABED';'ABCD';'AEFD';'ADFG'},{'ABCDEFG'}};
I want to extract all cells from X and convert each to a double.

2 Comments

Post a sample of your data.
@Craig: Please post all required information inside the question. Comments run out of view, if other comments are posted later.

Sign in to comment.

Answers (2)

So:
cellfun(@str2double,{{'1','3','34'},{'45'},{'12','1017'}},'uni',false)

5 Comments

Thanks. How could i use this in a loop if I have, say, X={1 by 7} cell?
for i=1:7
cellfun(@str2double,{X},'uni',false)
end
That doesn't seem to work. Also what is the 'uni' argument?
Craig
Unfortunately this method doesn't work. It throws out NaN as I am dealing with
cellfun(@str2double,{{'A','B','C'},{'D'},{'E','F'}},'uni',false)
Is what I am trying to do possible or am I going to have to alter my methodology?
How do you convert an 'A' to a double? Do you want the ASCII version of it?
That is currently what I am thinking I will have to do. Not sure how to convert a whole cell to ascii values though.
double('A')
Rather than string to double which interprets the value not the ascii. What is your big picture here, what are you trying to do?

Sign in to comment.

Jan
Jan on 17 Sep 2013
Edited: Jan on 17 Sep 2013
'A' cannot be converted to a double, because it is a letter. The same matters your 'AB', 'ABC', etc also. So please explain, what you expect as output.
You have recognized this problem already: "MATLAB doesn't seem to enjoy working with letters". But as long as such operations are not defined, how could we or Matlab know, what you are trying to do?

4 Comments

It is difficult to summarise but I will try. I have a 15 letters (A-O) and as part of my code I have looped through all poss combinations of these letters (in groups of 2-15). For example
{AB; AD ...} (groups of two)
all the way to
{ABCDEFGHIJKLMNO} (groups of 15) [everything in between also!]
I also have pairings of these letters (for example)
[A, B; D, J; J, O]
And basically I want a way to run through all the combinations I have of letters and remove the ones where BOTH letters in each row above (in X) exist.
The question I am putting to you all is a small part of how I am attempting to achieve this but looks as if I may need another method. Would you have any initial ideas?
I still do not understand, what you want to achieve. How does your "{AB; AD ...}" look in Matlab syntax? Here "AB" are not two letters but the name of a variable. What does this mean:
...remove the ones where BOTH letters in each row above (in X) exist.
? What is the relation to the conversion to doubles?
Craig
Craig on 17 Sep 2013
Edited: Craig on 17 Sep 2013
Say I have, x=
'A' 'B' 'D'
'A' 'B' 'E'
'A' 'B' 'F'
'A' 'B' 'G'
'A' 'B' 'H'
'A' 'B' 'I'
'A' 'B' 'J'
'A' 'B' 'K'
'A' 'B' 'L'
'A' 'B' 'M'
'A' 'C' 'D'
'A' 'C' 'E'
And pairs of letters, y=
'A' 'C'
'E' 'D'
'E' 'C'
'J' 'I'
'J' 'H'
'M' 'L'
'V' 'T'
'V' 'U'
'Q' 'N'
'Q' 'O'
'Q' 'P'
So I want to loop through each row of y with x so it returns a "new x" =
'A' 'B' 'D'
'A' 'B' 'E'
'A' 'B' 'F'
'A' 'B' 'G'
'A' 'B' 'H'
'A' 'B' 'I'
'A' 'B' 'J'
'A' 'B' 'K'
'A' 'B' 'L'
'A' 'B' 'M'
Where some rows have been removed as they contain both letters contained in any row of y.
Thanks for helping out. It is hard to explain.
This is still not valid Matlab syntax:
x=
'A' 'B' 'D'
'A' 'B' 'E'
...
The details matter. So please post code, which we can run by copy&paste.
In "new x" (better use a valid Matlab name here also) the contents of "x" has been modified and some rows are removed. But there is an infinite number of possible algorithms to convert "x" to "new x". Then it is not clear, if you have managed to solve the procedure shown in the comment or if this belongs to the problem.
The only line of code or sentence I understand from your question yet is:
X = {{'AB';'AC';'AE':'AD'},{'ABC';'ACD'},{'ABED';'ABCD';'AEFD';'ADFG'},{'ABCDEFG'}};
Unfortunately I do not see any relation to e.g. your above comment or the text of the original question.
Craig, I know problems are hard to explain. It seems like the the level of abstraction is too high to allow a clear explanation. So try to solve the problem from another direction: Explain the actual problem you want to solve by this method.

Sign in to comment.

Categories

Asked:

on 16 Sep 2013

Community Treasure Hunt

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

Start Hunting!