access data at specific position in cell

조회 수: 18 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by