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

조회 수: 4 (최근 30일)
Ranu Ghafour
Ranu Ghafour 2022년 9월 11일
댓글: Ranu Ghafour 2022년 9월 13일
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
David Hill
David Hill 2022년 9월 13일
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?
Ranu Ghafour
Ranu Ghafour 2022년 9월 13일
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".

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2022년 9월 13일
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
Ranu Ghafour
Ranu Ghafour 2022년 9월 13일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by