access data at specific position in cell

6 Ansichten (letzte 30 Tage)
Christian
Christian am 12 Jun. 2018
Beantwortet: Christian am 12 Jun. 2018

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

Akzeptierte Antwort

Christian
Christian am 12 Jun. 2018
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);

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by