Search code examples
matlabmultidimensional-arraylarge-data

Limiting large array to 1D in MATLAB


I'm working with XShooter data and for galactic corrections, I'm using ccm_unred in MATLAB. The problem is

funred = flux*10.^(0.4*A_lambda);

this line of code generates a 29686 X 29686 double array. I want only one side of it, I can do it by reassigning funred as funred = funred(:,1) but this piece of code also takes 57 seconds to be executed and uses up my CPU and RAM too much for my laptop to stay stable. Is there any method by which I can limit the generation of funred to only (:,1) from the beginning?


Solution

  • You say that your code generates a 29686 X 29686 matrix, however you are doing element-wise operations in your equation. That means that either flux or A_lambda bust be 29686 X 29686. Just slice the ones that are that size!

    Assuming one of them is 29686 X 29686

    funred = flux(:,1)*10.^(0.4*A_lambda(:,1));
    

    Just remove the (:,1) of the one that is is not a matrix.

    If both of them are a matices, then you can not do it, as flux*... would need the whole matrix to operate.