I get an error, could you guys help me to figure out?

2 views (last 30 days)
Error using bsxfun Out of memory. Type HELP MEMORY for your options.
Error in classreg.learning.internal.wnanmean (line 12) X = bsxfun(@times,X,W);
Error in pca (line 284) mu = classreg.learning.internal.wnanmean(x, vWeights);
Error in princomp (line 29) [varargout{1:nargout}]=pca(varargin{1},'Algorithm','svd','Economy',fEconomy);
Error in pca_for_Zhen (line 36) [coeff, score, latent]=princomp(data,'econ');
[fname pname]=uigetfile('*.*','Please click any image in your folder');
cd(pname);
filenamelist=dir(pwd);
nel=length(filenamelist);
index=0;
sampleImage=im2double(imread(fname));
vsampleImage=sampleImage(:);
[numRows numCols]=size(sampleImage);
data=zeros(size(vsampleImage,1),200);
label='Zhen sample';
for i=3:1:102
% here you are try from 3 (the first image with signal) to any arbitrary
% number and find out how many frames you need in your case. This number
% is different since the exposure time and frame rate is different from
% our setup to your imaging setup.
if filenamelist(i).isdir~=1
if mod(i,1)==0
index=index+1
fname=filenamelist(i).name;
tempData=im2double(imread(fname));
data(:,index)=tempData(:);
end
end
end
[coeff, score, latent]=princomp(data,'econ');
n=score>=0;
posscore=n.*score;
m=score<=0;
negscore=m.*score;
figure
for j=1:9
subplot(3,3,j)
pcolor(reshape(score(:,j),numRows,numCols));axis image;shading flat;axis ij;
text(5,20,[label ' ' sprintf('%d',j)],'Color','w','FontWeight','bold')
axis off;
colormap jet;
end
cd('..');
%print(gcf,'-dpdf',[label ' components.pdf']);
%rgb overlay
impos=zeros(numRows,numCols);
%positive
impos(:,:,1)=reshape(posscore(:,2),numRows,numCols);
impos(:,:,2)=reshape(posscore(:,3),numRows,numCols);
impos(:,:,3)=reshape(posscore(:,4),numRows,numCols);
for k=1:3
impos(:,:,k)=impos(:,:,k)/max(max(impos(:,:,k)));
end
figure
image(impos);
axis image;
title([label ' Positive']);
%print(gcf,'-dpdf',[label ' positive.pdf']);
%negative
imneg=zeros(numRows,numCols);
imneg(:,:,1)=reshape(-negscore(:,2),numRows,numCols);
imneg(:,:,2)=reshape(-negscore(:,3),numRows,numCols);
imneg(:,:,3)=reshape(-negscore(:,4),numRows,numCols);
for k=1:3
imneg(:,:,k)=imneg(:,:,k)/max(max(imneg(:,:,k)));
end
figure
image(imneg);
axis image;
title([label ' Negative']);
%print(gcf,'-dpdf',[label ' negative.pdf']);
imoverlay=zeros(numRows,numCols); for k=1:3
imoverlay(:,:,k)=impos(:,:,k)+imneg(:,:,k);
imoverlay(:,:,k)=imoverlay(:,:,k)/max(max(imoverlay(:,:,k)));
end
figure
image(imoverlay);
axis image;
title([label ' Overlay']);
  3 Comments
Guillaume
Guillaume on 1 Sep 2014
Edited: Guillaume on 1 Sep 2014
The error has nothing to do with Java or the Java heap memory. Increasing the heap memory won't help solve the error. If anything it will make it even more likely as it'll reduce the memory available for matlab arrays.
Zhen, I would put a breakpoint on the line with the call to princomp and when the breakpoint is hit, look at what memory and whos tell you.
Stephen23
Stephen23 on 1 Sep 2014
Edited: Stephen23 on 1 Sep 2014
Zhen Weng: please do not post the same question multiple times.
Your last post of this question generated two comments giving advice that you should format your code to be more readable, and also to give some details of what you understand of the problem. This advice is aimed to make it easier for people to help you: spamming the same question multiple times will discourage people from helping you. Please simply edit your original question, or add comments to clarify details.

Sign in to comment.

Answers (2)

Iain
Iain on 1 Sep 2014
The error is that something is using too much memory. If your images are huge, this is a possible result.
You have a few ways of dealing with it:
1. Increase the amount of RAM you have on the system you're using.
2. Reduce the amount of stuff you're running to increase usable RAM (e.g. outlook, word, excel, etc.)
3. Reduce the amount of RAM you need. - Try with 2 files, rather than 101.

xing peng
xing peng on 19 Mar 2018
Edited: Walter Roberson on 19 Mar 2018
for the question of:
Error in princomp (line 29) [varargout{1:nargout}]=pca(varargin{1},'Algorithm','svd','Economy',fEconomy);
please try set path as the default.

Categories

Find more on Recognition, Object Detection, and Semantic Segmentation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!