Accessing individual contents of cell array for large amount of cells

  • Permalink
  • submit to reddit
  • Email
  • Follow


I have data thats in a cell in form of doubles, and depending on the data set, the length of this cell can range from about 20 to over 100. I need to access the contents of this cell array individually. I know how I can do this using deal, as in the example from doc:

[a,b,c,d] = deal(C{:})

My question: is there a method for automatically creating an array like [trial1 trial2 trial3 ... trial99] for varying lengths (that are specific to the cell length, of course) without actually doing it manually each time?

Sorry if it's confusing...

Thanks in advance!

Ashley
0
Reply Ashley 4/9/2010 8:22:04 PM

See related articles to this posting

"Ashley " <namehere@thisplace.com> wrote in message <hpo29c$n7l$1@fred.mathworks.com>...
> I have data thats in a cell in form of doubles, and depending on the data set, the length of this cell can range from about 20 to over 100. I need to access the contents of this cell array individually. I know how I can do this using deal, as in the example from doc:
> 
> [a,b,c,d] = deal(C{:})
> 
> My question: is there a method for automatically creating an array like [trial1 trial2 trial3 ... trial99] for varying lengths (that are specific to the cell length, of course) without actually doing it manually each time?

No. The actual data in each of the cells is physically in different parts of memory. When you concatenate some or all of them into a single variable you have to copy all of the individual data contents into a new single block of memory. That can only be done by manually doing it each time.  The alternative is to copy *everything* to one array and then access slices of that array. This latter approach has the advantage that it will ultimately will be faster to access your data this way than concatenating the individual cells each time.

James Tursa
0
Reply James 4/9/2010 8:44:05 PM

"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hpo3il$d9o$1@fred.mathworks.com>...
> "Ashley " <namehere@thisplace.com> wrote in message <hpo29c$n7l$1@fred.mathworks.com>...
> > I have data thats in a cell in form of doubles, and depending on the data set, the length of this cell can range from about 20 to over 100. I need to access the contents of this cell array individually. I know how I can do this using deal, as in the example from doc:
> > 
> > [a,b,c,d] = deal(C{:})
> > 
> > My question: is there a method for automatically creating an array like [trial1 trial2 trial3 ... trial99] for varying lengths (that are specific to the cell length, of course) without actually doing it manually each time?
> 
> No. The actual data in each of the cells is physically in different parts of memory. When you concatenate some or all of them into a single variable you have to copy all of the individual data contents into a new single block of memory. That can only be done by manually doing it each time.  The alternative is to copy *everything* to one array and then access slices of that array. This latter approach has the advantage that it will ultimately will be faster to access your data this way than concatenating the individual cells each time.
> 
> James Tursa


Thanks, you've saved me a few hours. 

I actually separated the data and put them into nonuniform cells (that's the only way I know how to separate data based on something without having to do it for each new data set) based on the trial number, so i'd like to keep the data separated because I need to manipulate the data within a trial - separate from the other trials. Is there a more efficient way of doing this?

*fyi: trial - from doing a repeated task

Thanks in advance!

Ashley
0
Reply Ashley 4/9/2010 10:37:03 PM

"Ashley " <namehere@thisplace.com> wrote in message <hpoa6f$l41$1@fred.mathworks.com>...

> Thanks, you've saved me a few hours. 
> 
> I actually separated the data and put them into nonuniform cells (that's the only way I know how to separate data based on something without having to do it for each new data set) based on the trial number, so i'd like to keep the data separated because I need to manipulate the data within a trial - separate from the other trials. Is there a more efficient way of doing this?
> 
> *fyi: trial - from doing a repeated task
> 
> Thanks in advance!
> 
> Ashley

I found a way to extract it to a double in separate columns. Problem solved!

Ashley
0
Reply Ashley 4/12/2010 4:39:05 PM
comp.soft-sys.matlab 201586 articles. 514 followers. Post

3 Replies
304 Views

Similar Articles

[PageSpeed] 1

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

using cell arrays and accessing specific content
Hi guys, I would like to know how to access a cell arrays sectors/ contents which is based on a relational operator. To make it clear I have a cell array Ra={12 123 12 21312 434 132 221 12 123 3 123 131 12} ...... its very lengthy about 2000 matrices inside I would like to access and take out those values which are greater than 100 and less than (100+tol) my tolerance is usually 20. The catch is I wont have exactly 100 in my cell array. So I need to chose a tolerance value. Guys plz help me out on this. I was trying to convert to a normal matrix using cell2mat and then using relational o...

Overly large amount of space used to save a cell array on the hard-drive
Hi, I've got a problem when saving some data.I have a 7*7 cell array, each cell containing a structure array, and I plan to get it bigger by adding new data. Anyway, when I use the function whos, matlab tells me that these data take 117 Kb - no problem so far. However when saving it to the hard drive -with the function save-, the final size is 31 Mb. And this discrepancy becomes worse and worse as I add new elements to my cell array. THe problem is not so much the final size on the hard-drive, but it gets longer and longer when loading and saving the file. Any help on this would be much w...

Access to cell array in cell array
Hallo. I have a problem with a cell array. It's a 12x2 cell array. And in the second column in each row of this cell array is again a 13x1 cell array. In the 8th cell there is a column vector. I tried to gain access to this column vector in the 8th cell for finding the minimum at once of all 12 cells in the second column. But I failed. It looks like that: samples_merged{i,2}{8,:} where i runs from 1 to 12. I am able to solve the problem with a loop, sure, but if anyone comes up with an idea without a loop, I would be happy. Kind regards, Gudrun In article <10143048.1204191328840.J...

Breaking Up Large Cell Array into Smaller Cell Arrays
Hello, I have a unique problem. Right now I have a large cell array and I want to break that cell array into smaller cell arrays. Here is a portion of the large cell array: C = [1x35 char] [1x39 char] 'ALAMEDA' 'CA' [1x30 char] [1x20 char] 'ALAMEDA' 'CA' [1x30 char] [1x20 char] 'LUDINGTON' 'MI' [1x30 char] [1x20 char] 'LUDINGTON' 'MI' Now, for this test case I want to break this into two smaller cell arrays according to...

cell contents to non-cell array object
Hopefully a trivial question: This part of my program below opens datafile with two columns(and header) serial date and temp. Reads in serial date, converts to string date and hopefully writes out string date and temp value. Getting error that says: "Cell contents assignment to a non-cell array object." Crashes during 2nd time thru for loop on stringd{i} line. Tried {} brackets, (), parentheses...not sure if strings need to be exact same size. Any suggestions? Thanks, Sheryl [fid] = fopen(filename_in,'rt'); [A,B] = textread(filename_in,'%f %f','headerlines',3...

??? Cell contents reference from a non-cell array object.
In the following code I receive the following error relating to my for loop: ??? Cell contents reference from a non-cell array object. What is the problem? Cheers, Saskia %Produce .jgw files %read in data [im_id, ps, e, n]=textread('mosaic.txt', '%n%n%n%n'); %process [x,junk]=size(ps); zero1=zeros(x,junk); zero2=zeros(x,junk); nps=ps*-1; %write for i=1:x M=[ps(i),zero1(i),zero2(i),nps(i),e(i),n(i)]; dlmwrite(['C:\World files\',im_id{i},'.jgw'], M, 'newline', 'precision', 9) end ...

Cell contents reference from a non-cell array object.
Hi all A.data{1,1}{1}(1) gives me this ??? Cell contents reference from a non-cell array object. do you know why ? any suggestions In article <ef5b8a1.-1@webcrossing.raydaftYaTP>, aa <dragonboy.ali@gmail.com> wrote: >Hi all >A.data{1,1}{1}(1) >gives me this >??? Cell contents reference from a non-cell array object. >do you know why ? >any suggestions We can deduce that either A.data is not a cell array, or else A.data{1,1} is not a cell array. But as to -why- this is so... Sorry, Magic 8-Ball Is Out of Order. -- There are some ideas so wrong that...

Cell contents assignment to anon-cell array object.
I have two listbox listbox one and listbox 2 the user should choose a value from the listbox 1 and add it to the list box 2 %% get the sellected value from listbox 1 list1_val= get(handles.listbox1,'Value'); list1_str= get(handles.listbox1,'String'); handles.mc1=list1_str{list1_val}; % handles.mw1= material code handles.mw1=str2double(get(handles.MW,'String')); %% put it in the listbox 2 % get the value of the sellected item list2_val= get(handles.listbox2,'V...

Cell contents reference from a non-cell array object. #2
&#305; have two popup menu in gui first &#305; choese one of them and variable size 150*2 matris then when &#305; callback another for 150*4 matrix it gives this error &#305; cant handle it pls help me what is the reason "ali " <rebelfirst@gmail.com> wrote in message <h6dl0f$3uk$1@fred.mathworks.com>... > &#305; have two popup menu in gui > first &#305; choese one of them and variable size 150*2 matris > then when &#305; callback another for 150*4 matrix it gives this error &#305; cant handle it pls help me what is the reas...

Cell contents reference from a non-cell array object...but only in GUIDE...
I'm running GUIDE and am generating a GUI to interact with a simulation. Basically, I'm trying to create a cell array to contain a log of simulation-generated messages. I have initialized the cell array as a global variable so that it can be updated in different functions. Since I don't want to lose previous messages (they're being saved to get written to file later), the array needs to dynamically concatenate itself with the messages that come in. I have a little code snippet that works in the command window, but when I implement it into the rest of my code, I get my favorite ...

Pb : Cell contents assignment to a non-cell array object
Hello, I have a problem with insering data in a database. I open a database,select a field of the database and try to insert a matrix containing characters. I define this matrix like a cell array. But the result of the insertion is: Cell contents assignment to a non-cell array object Do you have an idea of what is the problem? my program is: db=dbase(bdd,user,password,12) rs=rset(db,'select * from table1 where Name =''Morizet''',1) xc = fields(rs) iris_matrice = {'image001';'image002';'image003';'image004';'image005';'...

??? Cell contents assignment to a non-cell array object error when using odes15s
I've been using odes15 to solve variouos differential equation models, but over the past couple of days I seem to be getting this error when I try and run most of my programs, even ones that haven't been altered: ??? Cell contents assignment to a non-cell array object. Error in ==> cellstr at 38 c{i} = s(i,:); Error in ==> cell.ismember at 28 if ischar(a), a = cellstr(a); end Error in ==> funfun\private\odefinalize at 19 fullstats = ismember(solver,{'ode15i','ode15s','ode23s','ode23t','ode23tb'}); Error in ==> ode15s at 986 s...

Individual elements of an array with a cell array
Say I define a cell array as follows: c = {'Name', 'Surname', grades}; where grades is a numerical vector, defined as follows: grades = [7 8 6 10]; My question is, how can I have c look like this: c = 'Name' 'Surname' 7 8 6 10] instead of like this, as Matlab currently arranges it: c = 'Name' 'Surname' [1x4 double] Many thanks for any help! The title of my post should be "Individual elements of an array withIN a cell", unfortunately cannot edit it... "Catali...

Access a cell array
So I have a cell array consisting of numbers and strings, and want to remove a row of them.. (say for example phonebook data read from an excel sheet) Example Program: [~,~,pbook] = xlsread('Phonebook'); pbook = 'NAME' 'LAST NAME' 'NUMBER' 'John' 'Smith' [ 123456] 'Adam' 'West' [ 987654] 'Harry' 'Potter' [ 567123] 'James' 'Bond' [ 007007] How would I write a code to look for Ha...

cell array contents
is there a easier way to find the sum of the cell? y = [1x3 double] [1x100 double] [8x6 double] myCell = cell(1,3) myCell{1,1} =[1,4,-10;] myCell{1,2} =[9,5,3,8,9,2,1,0,8,9,3,5,0,7,2,5,1,0,5,9,6,5,1,1,0, 2,2,9,4,9,1,7,3,2,0,3,2,7,6,5,5,2,6,9,2,6,8,3,4,6, 4,5,6,1,8,4,5,2,5,8,7,3,8,6,1,6,0,3,4,6,7,9,4,6,4, 1,8,4,3,5,0,5,9,8,5,3,2,0,0,2,7,3,4,8,1,9,0,2,6,5;] myCell{1,3} = [25,21,35,29,99,69;1,56,62,54,3,94;92,4,45,83,2,91; 61,3,9,65,58,100;59,90,21,28,26,63;82,80,66,18,98, 65;65,62,31,44,80,56;44,86,83,24,65,96;] cellfun(@(x) sum(x( : ),myCell) % Sum of total in each cell sumy =...

accessing cell arrays
I have a cell array, that looks like the following A = [2X2 double array] [2X3 double array] [2x4 double array] I would like to try to find a way to access specific elements of each element of the elements of the cell array. For example ideally i would like to find a way to access the first element and 3 element of the above cell array which i know i can do with the following call: A([1 3]). I would like to then find a way to access the first element of the first matrix and the second element of the second matrix, which i imagine would look something like A([1 3])([1 2]), except that retur...

cell array access
Hi! Can anybody help me on this topic? Let: c=cell(3,1) c{1}=1:1:10; c{2}=1:1:10; c{3}=1:1:10; %why wont c{1:3}=1:1:10 work? --I would like to retrieve the last element of every cell entry-is this possible with out any for loops and temp assignment--? Thank You, Felix. Felix wrote: > c=cell(3,1) > %why wont c{1:3}=1:1:10 work? Hi, you should read the documentation : <http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch_da37a.html> try this : c=cell(3,1); [c{:}]=deal(1:10) > retrieve the last element of every cell entry with out > any for loops and ...

to create a cell array with the same content
Hi all, I want to create a cell array with the same content give the size for the cell. For instance, A ={ 'cell'; 'cell'; 'cell'; 'cell'; 'cell'}; I need to create a large list, so I cannot type in the cell elements one by one. It is also undesirable to use loops fill the content. So far, I have not find a function that create a cell array with the same content. (Something like ones(5,1)*10 for creating vectors). If anyone knows, could you please let me know? Thank you in advance. Wendy C = repmat({'mycontent'},2,3) ...

multiple access to a cell array
Hello, I have a <1x4 Cell> where each member is a struct. such that: a{1} is a struct, a{2} is a struct and so on. I want to be able to run some function on all my a{:}.Time for example. let's say something like sum(a{:}.Time). How do I do it? Thanks. Y. Yoav Mor wrote: > > > Hello, > > I have a <1x4 Cell> where each member is a struct. > such that: > a{1} is a struct, a{2} is a struct and so on. > > I want to be able to run some function on all my a{:}.Time for > example. let's say something like sum(a{:}.Time). > > How do I do it? ...

how to access cell array as a numeric
Hello all, If I enter radius thru dialogue box (which is needed for me) rad1 = inputdlg('enter radius') rad1{1} * 0.5 ans = 24.0000 23.0000 24.5000 why answer is like this ?? Eventually I need to access this radius as a numeric how to do this ? Thanks ina dvance for help bdon wrote: > > 24.0000 23.0000 24.5000 > > why answer is like this ?? Hi, I guess that the radius was... 0.1 ! Right ? Because INPUTDLG returns a string not a number : You entered "0.1", so : a='0.1' a*0.5 Now, try this : rad1 = inputdlg('enter radius') str2num(rad1{...

accessing cell arrays #2
I have a cell array (A) of length 100 and each element is a [5X1 double]. Now I can access individual members of each element of the array by doing something like A{3}(2) which would give me the 2nd member of the third element in the array. How do I access the 2nd member of say, the first 10 elements in the array. Something like A{1:10}(2) does not work. Any help would be appreciated. thanks! cupricwhistle wrote: > > > I have a cell array (A) of length 100 and each element is a [5X1 > double]. Now I can access individual members of each element of the > array by doing somet...

publish content of cell array
Hi, i want to publish MATLAB results in a word document and my question is, if there is a way to display the content of cell arrays without square brackets. Of course I can first use xlswrite but it would be easier to publish direktly. Thank, martin ...

accessing cell arrays globally
I need to have multiple functions contribute to building a cell array of strings. It would be ideal to declare my cell array globally in each function. However, the 'global' command seems only to work with matrices, not cell arrays. Is there any way make a cell array a global variable in MATLAB? Matthew Walsh wrote: > > > I need to have multiple functions contribute to building a cell > array > of strings. It would be ideal to declare my cell array globally in > each function. However, the 'global' command seems only to work > with > matrices, not cell ...

Accessing cell matrix contents
How to convert a cell matrix into matrix of its contents reliably? My code: .... matrix=3D[cellmatrix{:}]; .... Applying the code to a "cellmatrix" which is 15x1 cell, all members char (o= f different lengths) works properly: the output "matrix" is 1x15 cell, memb= ers still each char. The code also worked right on a few previous cycles. On the next cycle, however, "cellmatrix" is still cell (now 16x1), all memb= ers still char, starting with members '5' 1x1 char, '5' 1x1 char, then '4.0= 147' 1x6 char, '0.9583' 1x6 ch...