help-octave
[Top][All Lists]

## Re: array cell...... Find index from value

 From: Przemek Klosowski Subject: Re: array cell...... Find index from value Date: Wed, 25 Jul 2018 17:02:18 -0400 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

```On 07/25/2018 03:15 PM, shivax wrote:
```
```i writed GG as example.
But i need to execute code on this array cell:

GG
[7,2] =

here there is several null cells..

i've try this code:

```
```a = cellfun (@(x) ~isempty (x) && (x ==122), string_dat_rp(:,2));
find(a, 1, 'first')
```
```
ans = [](0x1)
```
First, take a look at how Markus wrote his example: you can literally start a fresh version of Octave and paste a copy of his code into it. You give some results, but I had to reverse-engineer them to populate the cell array the way I think you have it. I think I got it right, but please try to come up with a nice compact example so that everyone can follow and replicate it. For instance, there's no point in using large indices like {54,2}---it just results in large output printouts. Why not use
```GG{3,2}=120
GG{5,2}=122

```
Next, can you give a brief background as to why you're using cell arrays? THis is an advanced topic, and most  numerical code just uses regular arrays (eg. Gx(3,2)=6). Cell arrays are useful when your arrays are weird, like when they contain  submatrices of different size or even dimension---this doesn't seem to be the case for you.
```
```
Then, you seem to be looking for an associative array---looking for an index of a cell containing a specific value. Perhaps you could write your code accordingly---maybe, if your specific values are indeed small integers, use THEM as indices and store the coordinates : HH(120) = 54; HH(123)=23
```
```
Then, assuming you really want to work with cell arrays, you can play with various indexing modes: for instance observe the difference between GG{3,2} and GG(3,2). Octave is interactive, so you're supposed to build longer expressions by trying their pieces on your data. For instance, since GG(3,2) returns cells,  you can do a=GG(:,2) and then look at the result:
```    whos a GG
```
and it'll tell you that they both are cell arrays. You can then use cellfun, and adapt the @(X) function to do what you need to do. Again, however, it would be best if you tried to explain (with concrete, self-contained examples) what do you want to do.
```

```