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

  • SEARCH
  • Home
  • 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 6943687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:11:18+00:00 2026-05-27T13:11:18+00:00

I am loading a quite large matrix into Matlab. Loading this matrix already pushes

  • 0

I am loading a quite large matrix into Matlab. Loading this matrix already pushes Matlab to its limits – but it fits.

Then I do the following and I get an out-of-memory error.

data( :, 2:2:end, :, : ) = - data( :, 2:2:end, :, : );

Is Matlab allocating a new matrix for this operation? I would assume this operation would not need extra memory. How do I force Matlab to be more efficient for this?

Bonus question:

‘data = permute(data,[1 2 3 4 5 12 8 7 6 9 10 11]);’

Can matlab do this in-place?

  • 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-27T13:11:19+00:00Added an answer on May 27, 2026 at 1:11 pm

    There are a few constraints (further to those from Loren’s block cited by John):

    • Your code must be running inside a function
    • You must have no other aliases to ‘data’

    The ‘aliases’ thing is both important and potentially hard to get right. MATLAB uses copy-on-write, which means that when you call a function, the argument you pass isn’t duplicated immediately, but might be copied if you modify it within the function. For example, consider

    x = rand(100);
    y = myfcn(x);
    % with myfcn.m containing:
    function out = myfcn(in)
      in(1) = 3;
      out = in * 2;
    end
    

    In that case, the variable x is passed to myfcn. MATLAB has value semantics, so any modifications to the input argument in must not be seen in the calling workspace. So, the first line of myfcn causes the argument in to become a copy of x, rather than simply an alias to it. Consider what happens with try/catch – this can be an in-place killer, because MATLAB has to be able to preserve values if you error out. In the following:

    % consider this function
    function myouterfcn()
      x = rand(100);
      x = myfcn(x);
    end
    % with myfcn.m containing
    function arg = myfcn( arg )
      arg = -arg;
    end
    

    then, that should get in-place optimisation for x in myouterfcn. But the following can’t:

    % consider this function
    function myouterfcn()
      x = rand(100);
      x = myfcn(x);
    end
    % with myfcn.m containing
    function arg = myfcn( arg )
      try
        arg = -arg;
      catch E
        disp( 'Oops.' );
      end
    end
    

    Hope some of this info helps…

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

Sidebar

Related Questions

This is probably quite a simple question but very hard to google! I'm loading
I am quite sure I've seen the answer to this question somewhere, but as
I am loading quite a lot of rich text into a RichTextBox (WPF) and
I'm quite stumped on this issue. I have a large library of H.264 mp4
Sorry for the vague title, but not quite sure how to summarize this one.
Loading images into Flex (size < 100kb) causes IE7 memory increase by a megabyte
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
When loading XML into an XmlDocument, i.e. XmlDocument document = new XmlDocument(); document.LoadXml(xmlData); is
After loading a PHP template (using jQuery's load function), this simple script won't make
while loading getfptex(got it from CTAN) batch file ,when i'm extracting this batch file

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.