Working with cells of letters
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2013-9-17
@Craig: Please post all required information inside the question. Comments run out of view, if other comments are posted later.
回答(2 个)
Sean de Wolski
2013-9-16
So:
cellfun(@str2double,{{'1','3','34'},{'45'},{'12','1017'}},'uni',false)
5 个评论
Sean de Wolski
2013-9-17
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?
Jan
2013-9-17
编辑:Jan
2013-9-17
'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 个评论
Jan
2013-9-17
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!