Info

This question is closed. Reopen it to edit or answer.

"To RESHAPE the number of elements must not change".This error occurs in line18.how to correct this error?

1 view (last 30 days)
function out=load_database();
% We load the database the first time we run the program.
clear all;
close all;
clc;
persistent loaded;
persistent w;
if(isempty(loaded))
v=zeros(10304,400);
for i=1:2
cd(num2str(i));
k=1;
img=dir('*.jpg');
nfiles=length(img);
disp(nfiles)
for j=1:12
a=imread(strcat('Image',num2str(k),'.jpg'));
v(:,(i-1)*12+j)=reshape(a,size(a,1),size(a,1),1);
k=k+20;
end
cd ..
end
w=uint8(v); % Convert to unsigned 8 bit numbers to save memory.
end
loaded=1; % Set 'loaded' to aviod loading the database again.
out=w;

Answers (1)

James Tursa
James Tursa on 3 Jan 2019
Edited: James Tursa on 3 Jan 2019
This expression is only going to work if size(a,1)*size(a,1) = numel(a):
reshape(a,size(a,1),size(a,1),1);
What are you trying to do with that line of code? What is size(a)?

Community Treasure Hunt

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

Start Hunting!