How can I avoid the "out of memory' for the following code?

I have one set of data that has multiple matrices of 40000x10800. I want to extract those matrices column by column, clear it from zeros values, and the save them in another matrix. but when I ran the following code, it gives the "out of memory" message. Please help me.
r=randi([0 10],40000,10800);
for i=1:1:10800
r_0=r(:,i);
r_0=r_0(r_0~=0);
r_1(:,i)=r_0;
end
Unable to perform assignment because the size of the left side is 36287-by-1 and the size of the right side is 36346-by-1.
I have adjusted the code like above because my dataset is more the 5 Gb, so I couldn't attach it.

6 comentarios

You forgot to attach the .mat files! We'll check back later for them.
If you have any more questions, then attach your data files with the paperclip icon after you read this:
I cannot attach files as I'm not allowed, but I can attacha screen shot of the data files below. it containes only numbers.
datafilt01.mat
data2.mat
Then at least give us code to create the variables, even if you just fill them with random numbers.
Come on, make it EASY for us to help you, not hard.
Ranu Ghafour
Ranu Ghafour el 12 de Sept. de 2022
Editada: Ranu Ghafour el 13 de Sept. de 2022
I couldn't attached my dataset due to its size, but I adjusted the code above which is similar to my original code. I really appreciate your kind support.
You cannot have a matrix with different number of rows or columns. What you are trying to do will not work. What are you really trying to do? What is the big picture?
The Bigger picture is that I have data series that has several matrices of 40000x10800 containing numbers. I got this data from a measurement. I want to plot several graphs for statistical analization, but before that I need to remove those cells in each column that has 0 value. However, when I run the code, it gives me an error of either "out of memory" or " size of left side and right size are not equal".

Iniciar sesión para comentar.

 Respuesta aceptada

Evidently you have enough memory to hold your variables, you just can't "plot several graphs for statistical analization". Since you can't "remove" zeros, which would leave the matrix with uneven/ragged borders, you should assign them to nan. Then you can use the 'omitnan' in functions like mean(), and functions like plot() will ignore them.
m(m==0) = nan;
% Get mean of matrix:
meanOfM = mean(m(:), 'omitnan');
% or plot each column:
[rows, columns] = size(m);
for col = 1 : columns
plot(m(:, col), '-');
hold on;
end
xlabel('row')
ylabel('Value of m')
grid on;

1 comentario

Thanks for you kind help. Actually I have to assign those column that I need for my plot or calculation to NaN, otherwise the system still cannot assign zero values of 40000x10800 in one line of code.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2021a

Preguntada:

el 11 de Sept. de 2022

Comentada:

el 13 de Sept. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by