Error using reshape syntax

14 views (last 30 days)
Wildan
Wildan on 4 Apr 2019
Answered: Walter Roberson on 4 Apr 2019
I'm new in Matlab. I want to reduce the size of the vector magnitude to smaller so that later I can use it for the KNN classification. So I try use 'reshape' to reduce the vector column size to 100
Error using reshape
To RESHAPE the number of elements must not change.
Error in Gabor2 (line 25)
rs = reshape(mag,1,250*250);
Here is my code..
%Pelatihan (Training)
folder_citra = 'data latih';
nama_citra = dir(fullfile(folder_citra, '*.jpg'));
jumlah_citra = numel(nama_citra);
for n = 1:jumlah_citra
% Membaca citra
Img = imread(fullfile(folder_citra, nama_citra(n).name));
% Resize citra
Img_resize = imresize(Img, [250 250]);
% Konversi citra RGB menjadi Grayscale
Img_gray = rgb2gray(Img_resize);
% Ekstraksi Ciri Tekstur Filter Gabor
wavelength = 4;
orientation = 90;
[mag,phase] = imgaborfilt(gray, wavelength, orientation);
rs = reshape(mag,1,250*250);
mag_kecil = imresize(mag,1/25);
training = reshape(mag_kecil,1,100);
end

Accepted Answer

Walter Roberson
Walter Roberson on 4 Apr 2019
reshape() can never be used to make an array smaller. It can only be used to change how a block of memory is indexed, with the number of elements having to stay the same.
You might be able to use resample() for your purposes.

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!