Error using reshape Size arguments must be integer scalars
조회 수: 6 (최근 30일)
이전 댓글 표시
The code below give me an error message "Error using reshape Size arguments must be integer calars"
n = ending_pts;
phi = (sqrt(5)-1)/2;
theta = 2*pi*phi*(0:n-1);
rho = (1:n).^phi;
[x,y] = pol2cart(theta(:),rho(:));
xy = 10*([x y]-min([x;y]))/(max([x;y])-min([x;y]));
popSize = 60;
numIter = 2e4;
a = meshgrid(1:n);
dmat = reshape(sqrt(sum((xy(a,:)-xy(a',:)).^2,2)),n,n);
[optRoute,minDist] = tsp_ga(xy,dmat,popSize,numIter,1,1);
this line gives the error
dmat = reshape(sqrt(sum((xy(a,:)-xy(a',:)).^2,2)),n,n);
can any one tell me how can i resolve it please!
thanks
댓글 수: 3
Geoff Hayes
2014년 5월 26일
Hi Mika - I wasn't really expecting the above. Have you stepped through the code to see what happens once n is set to ending_pts? It appears that
theta = 2*pi*phi*(0:n-1);
is only a 1x3 vector because ending_pts(1,1) is 3. Is this what you are expecting to happen? Or, how do you expect each row in the input matrix to be handled?
답변 (1개)
udayakumara mg
2019년 12월 3일
% APPLICATION of Zero-Crossing Rate descriptor
%% ---------------------------READING INPUT FILE----------------------------
% 'y': Audio data in the file, returned as an m-by-n matrix, where m is
% the number of audio samples read and n is the number of audio channels in
% the file.
% 'Fs': Sample rate, in Hz, of audio data 'y', returned as a positive scalar.
%'n_samples': Number of total samples of audio data
input_audio = 'uday.wav';
[y,Fs] = audioread(input_audio);
y = y * 2.^15; % original values into integer
n_samples = length(y);
%% --------------------------FRAMING---------------------------------------
% Objective: to segment the audio_input data into frames of fixed length
% 'frame_length': fixed length of the audio frame
% 'n_frames': Number of frames
% 'frames': Array that contains all frames data
% Dimension = (frame_length, n_frames)
% i.e. frames(67,3) : sample 67 of frame 3
frame_length = Fs/40; % Assuming Fs is integer.
% Frame length of 400 ms (for Fs = 16 kHz)
trailing_samples = mod(n_samples, frame_length);
frames = reshape( y(1:end-trailing_samples), frame_length, []);
n_frames = length(frames(1,:));
%% -------------------------Zero-Crossing Rate-----------------------------
[ zcr ] = ZCR( y, frames, n_frames, Fs );
%% -----------------------Hamming Windowing--------------------------------
h = hamming(frame_length);
h = repmat(h,1,n_frames);
w = frames.*h;
w_reshaped = reshape(w, 1, frame_length*n_frames);
%% --------------------------PLOTING---------------------------------------
% Objective: to plot the comparative of the audio input file vs windowed
% signal
figure;
subplot(2,1,1); plot(y); ylabel('Amplitude'); title('Audio input');
subplot(2,1,2); plot(w_reshaped, '.-');
xlabel('time'); ylabel('Amplitude'); title('Windowed signal');
%% -----------------------Energy computation-------------------------------
energy = sum(w.^2);
%% --------------------------PLOTING---------------------------------------
% Objective: to plot the comparative of the audio input file vs signal energy
figure;
subplot(2,1,1); plot(y); ylabel('Amplitude'); title('Audio input');
subplot(2,1,2); plot(energy, '.-');
xlabel('time'); ylabel('Energy (J)'); title('Signal energy');
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!