Azzera filtri
Azzera filtri

How to solve this error: Error using reshape To RESHAPE the number of elements must not change.

4 visualizzazioni (ultimi 30 giorni)
I am trying to run the following code but i am getting the error
Error using reshape
To RESHAPE the number of elements must not change.
Error in programm (line 35)
CC =reshape(C{1}, 2304, 3589*2);
Here is the code
clear;
tic;
DataX = zeros(28709,2304,'single');
DataY = zeros(28709,1,'single');
fid = fopen('train.csv');
C = textscan(fid, '%d', 2305, 'Delimiter', '",', 'Headerlines',1, 'MultipleDelimsAsOne', 1);
DataX(1,:) = C{1}(2:end);
DataY(1) = C{1}(1);
for i = 2:28709
if mod(i, 1000) == 0
i;
end
C = textscan(fid, '%d', 2305, 'Delimiter', '",', 'MultipleDelimsAsOne', 1);
DataX(i,:) = C{1}(2:end);
DataY(i) = C{1}(1);
end
fclose(fid);
toc;
DataX = DataX./255;
im = write_grid_images(DataX, [48 48], [10 10], 2, 1);
myfclf(1); imshow(im);
save data.mat DataX DataY;
tic;
fid = fopen('test.csv');
C = textscan(fid, '%s', 'Delimiter', '" ', 'Headerlines',1, 'MultipleDelimsAsOne', 1);
fclose(fid);
toc;
CC =reshape(C{1}, 2304, 3589*2);
TestX = zeros(2304,3589*2,'single');
for i = 1:2304
for j = 1:3589*2
TestX(i,j) = str2double(CC{i,j});
end
end
TestX = TestX'./255;
im = write_grid_images(TestX, [48 48], [10 10], 2, 1);
myfclf(1); imshow(im);
save test.mat TestX;

Risposte (1)

Jan
Jan il 10 Gen 2018
The message means, that C{1} does not have 2304*3589*2 elements. Because we do not have your input file, we cannot check this. But you can do this easily using the debugger. Type this in the command window:
dbstop if error
Then run the code again until it stops at the error. Now check the size of C{1}
size(C{1})
  7 Commenti
Guillaume
Guillaume il 11 Gen 2018
How to solve it now
I don't understand why you even ask the question.
Your code make the assumption that there are 2304*3589*2 strings in your file. There aren't 2304*3589*2 strings in your file. You solve that either by providing a file with the right number of elements or by making a different assumption. There's not much we can do about either.

Accedi per commentare.

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by