access data at specific position in cell

4 ビュー (過去 30 日間)
Christian
Christian 2018 年 6 月 12 日
回答済み: Christian 2018 年 6 月 12 日

Hello everybody,

I’d like to extract values out of a cell. In the beginning the cell (e.g. 1x3) contains other cell arrays, e.g.:

cell{1,1}

„hello“,“world“,500
„hello“,“world“,600

cell{1,2}

   „hello“,“USA“,1.5
   „hello“,“USA“,1.8

Now I want to code a for loop, which gets me the values after the last “,” in every cell. Right now I’m using this code within a for loop:

Position_komma{:,i} = strfind(cell{1,i}, ',');
Position_last_komma{:,i} = cellfun(@(v) v(end), Position_Komma{1,i});

And finally I convert the cells to a cell which does not contain other cells anymore:

cell=[cell{:}];
Position_last_komma=[Position_last_komma{:}];

So cell (now 2x3) looks like this:

„hello“,“world“,500		„hello“,“USA“,1.5		„hello“,“australia“,0.5999
„hello“,“world“,600		„hello“,“USA“,1.8		„hello“,“australia“,0.86

And Position_last_komma (2x3 double) like this:

16	14	20
16	14	20

Finally I need to get every string after the last komma in each cell, but I’m not able, to go into e.g. cell{1,1} and to the 17th digit in there. I hope I made my point clear and someone can help me!

Cheers, Christian

採用された回答

Christian
Christian 2018 年 6 月 12 日
I just found the answer by myself, adding a bracket after the cell makes you access specific position within the cell:
values{j,i}=cell{j,i}(Position_last_komma(j,i)+1:end);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by