How to assign a value to a cell nested in another cell
3 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone,
I have a seemingly simple problem but can't seem to figure out. I have something like this P={'Face1','Face2','Scene1','Scene2'}. What I would like to do is to assign a value to each of the element in P and still preserve the element's identity. For instance, the values could be assigned like this: Face1=4*5, Face2=23*6, etc.
However, when I do P{1,1}=4*5 then P becomes {20,'Face2','Scene1','Scene2}.This is not what I want since I've lost Face1. I'd like to keep the identity of each cell so when I call D{1,1} I'll get Face1, and when I call Face1, I'll get 20.
I hope the question is clear. Does anyone have any suggestions?
Thanks!
0 件のコメント
採用された回答
Jan
2014 年 4 月 23 日
This seems to be a magic question. What about this:
P = {'Face1','Face2','Scene1','Scene2'}
Face1 = 4*5
Or perhaps you want to use the string dynamically. Then using dynamic field names with structs is neat:
S.(P{1,1}) = 4*5;
disp(S)
S.Face1
その他の回答 (1 件)
Image Analyst
2014 年 4 月 23 日
I don't understand why you want this. Why do you? After all, the row and column are already numbers that uniquely identify every single element in your cell array . If you want just one number you could use sub2ind(). But I still don't know why .
2 件のコメント
Image Analyst
2014 年 4 月 23 日
Not sure I understand quite yet, but let me ask this first: Do you want P to be a 1-D array of cells, or a 2-D matrix of cells? You seem to have used it both ways.
And regarding your subject line about "a cell nested in another cell", does any of the cells in the array contain another cell ? Because to me, that's what nested means. If so, what's in the nested cell. Or do all the cells simply contain single, simple strings (character arrays)?
Have you read the FAQ on cells? http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F I think it gives a good intuitive explanation of cells and cell arrays.
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!