Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6784527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:00:21+00:00 2026-05-26T17:00:21+00:00

I’m dealing with very big data in matlab and used to store this data

  • 0

I’m dealing with very big data in matlab and used to store this data in matrices. I used to store my data by row, but since Matlab stores data column-wise I understand that reshaping my matrix so I index by column makes handling faster. Here’s an example of what I mean:


general parameters

nbr_channels = 20;
nbr_samples_per_channel = 3200000;
fake_data = randn(1, nbr_samples_per_channel);
ROI = 1200000 : 2800000;

assign data by row

data = nan(nbr_channels, nbr_samples_per_channel);
tic; 
for j = 1 : nbr_channels
    data(j, 1:nbr_samples_per_channel) = fake_data; 
end; 
toc;

% Elapsed time is 1.476525 seconds.

return data from row matrix

tic; 
for j = 1 : nbr_channels
    bla = data(j, ROI); 
end; 
toc;

% Elapsed time is 0.572162 seconds.

return all data from row matrix

tic; 
for j = 1 : nbr_channels
    bla = data(j, :); 
end; 
toc;

% Elapsed time is 0.589489 seconds.

assign data by column

data = nan(nbr_samples_per_channel, nbr_channels);
tic; 
for j = 1 : nbr_channels
    data(1:nbr_samples_per_channel, j) = fake_data; 
end; 
toc;

% Elapsed time is 0.299682 seconds.

return data from column matrix

tic; 
for j = 1 : nbr_channels
    bla = data(ROI, j); 
end; 
toc;

% Elapsed time is 0.260824 seconds.

return all data from column matrix

tic; 
f    or j = 1 : nbr_channels
    bla = data(:, j); 
end; 
toc;

% Elapsed time is 0.092983 seconds.

Summary Part1:

As we can see, accessing the data by column reduces the handling times by at least a factor of two!

But I don’t understand why cells are even more efficient! Have a look at this example:

assign data by cell

data = cell(1, nbr_samples_per_channel);
tic; 
for j = 1 : nbr_channels
    data{j} = fake_data; 
end; 
toc;

% Elapsed time is 0.000013 seconds.

return data from cell array

tic; 
for j = 1 : nbr_channels
    bla = data{j}(ROI); 
end; 
toc;

% Elapsed time is 0.260294 seconds.

return all data from cell array

tic; 
for j = 1 : nbr_channels
    bla = data{j}; 
end; 
toc;

% Elapsed time is 0.000022 seconds.

%%

Summary Part2:

This is orders of magnitude faster than what I have shown in Part1.

Question 1

why are access times to data stored in cells shorter than in matrices?

Question 2

Working with matrices is generally easier than with cells, because with a matrix on can do

my_matrix(100:20000, 1:3)

but with cells I can’t do this (as far as I know). Any alternatives on how to return specific elements from multiple cells at the same time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:00:22+00:00Added an answer on May 26, 2026 at 5:00 pm

    You are seeing different times because you are not doing equivalent things. To compare two of your cases:

    assign data by cell

    • You are creating a cell array row vector, and stuffing in a long double vector to each cell

    • Each loop iteration results in 1 assignment of a vector into a single slot in a cell array

    • There are ‘nbr_samples_per_channel’ number of assignments being done.

    assign data by column

    • you are going through the columns of a matrix, and assigning a vector to each element in each column

    • Each loop iteration, regardless of the shorthand colon : notation you used, resolves into many assignments. data(1:nbr_samples_per_channel, j) means ‘nbr_samples_per_channel’ assignments PER iteration.

    • overall, you are doing ‘nbr_samples_per_channel’ * ‘nbr_channels’ total assignments.

    To make my point, just re-write the loop without the colon operator to visualize all the assignments.

    for j = 1 : nbr_channels    
    
        n = length(fake_data)
    
        data(1,     j) = fake_data(1); 
        data(2,     j) = fake_data(1); 
    
        ... etc ...
    
        data(n - 1, j) = fake_data(n-1); 
        data(n,     j) = fake_data(n); 
    
    end
    

    So, to conclude, you are comparing two different things, so you can’t say one is really faster than the other, because they are not equivalent.

    If you just loop over a double array and a cell array, and do regular assignments….

    %% Setup samples and pre-allocate
    numberOfSamples = 100000;
    
    doubleData = nan(numberOfSamples, 1);
    cellData = cell(numberOfSamples, 1);
    
    randomValues = rand(numberOfSamples, 1);
    
    %% Assign N number of values to a double array
    tic; 
    for idx = 1 : numberOfSamples
        data(numberOfSamples) = randomValues(idx);
    end
    doubleTime = toc;
    
    %% Assign N number of values to a cell array
    tic; 
    for idx = 1 : numberOfSamples
        cellData{numberOfSamples} = randomValues(idx);
    end
    cellTime = toc;
    
    disp(sprintf('Double Array: %f seconds', doubleTime));
    disp(sprintf('Cell   Array: %f seconds', cellTime));
    

    You end up with:

    Double Array: 0.006073 seconds
    Cell   Array: 0.032966 seconds
    

    For your second question, is this what you are trying to do?

    >> bigCell = {1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16}
    
    bigCell = 
    
        [ 1]    [ 2]    [ 3]    [ 4]
        [ 5]    [ 6]    [ 7]    [ 8]
        [ 9]    [10]    [11]    [12]
        [13]    [14]    [15]    [16]
    
    >> subCell = bigCell(1:2, 3:4)
    
    subCell = 
    
        [3]    [4]
        [7]    [8]
    

    Notice that subcell is still a cell. By using ( ) ‘s and not { } ‘s to access the cell, you preserve it being a cell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to construct a data frame in an Rcpp function, but when I
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.