This post was updated on .
hi,
i'm this cell array of string : G example: G{1,2}=23 GG{2,2}=45 … GG{340,2}=98 i want Input: 98 and it return 340 it's possible using cellfun? i can't use it -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html |
GG{2,2}=45;
GG{340,2}=98; a = cellfun (@(x) ~isempty (x) && (x == 98), GG(:,2)); find(a, 1, 'first') Is this what you wanted? Markus -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html |
This post was updated on .
hi markus…
it's not correct :( output: ans = [](0x1) -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html |
It works for me with Octave 4.4.0 and 4.2.2. Did you copy and paste the 4
lines from my reply? Maybe it would help to run "clear all" before. What do you get for "which cellfun"? Markus -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html |
i writed GG as example.
But i need to execute code on this array cell: GG [7,2] = [8,2] = [9,2] = [10,2] = [11,2] = [12,2] = [13,2] = [14,2] = [15,2] = [16,2] = [17,2] = [18,2] = [19,2] = [20,2] = [21,2] = [22,2] = [23,2] = 123 [24,2] = [25,2] = [26,2] = [27,2] = [28,2] = [29,2] = [30,2] = [31,2] = [32,2] = [33,2] = [34,2] = [35,2] = [36,2] = [37,2] = [38,2] = [39,2] = [40,2] = [41,2] = [42,2] = [43,2] = [44,2] = [45,2] = [46,2] = [47,2] = [48,2] = [49,2] = [50,2] = [51,2] = [52,2] = [53,2] = [54,2] = 122 [55,2] = [56,2] = [57,2] = [58,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) -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html |
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) 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. |
Thank you for answer..
i've understand what is the problem... in my code i write: for hh=1:columns(sistemOrigEquity) dateString(gg,1)={datestr(datt(gg,1),1)}; dateString(gg,2)={num2str(cc)}; (i give to write in excel 'dateString') num2str convert number to a string..it's not correct.. I modify in : dateString(gg,2)={cc}; Now it's ok....i can to search index with your code.. thank you -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html |
Free forum by Nabble | Edit this page |