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 个评论
mika
mika 2014-5-26
hello,
>> ending_pts is a 148*2 matrice
ending_pts =
3 791
8 388
10 570
17 285
24 836
32 342
35 656
43 339
44 634
53 656
55 445
57 657
59 179
60 62
62 217
64 618
73 629
74 629
77 617
84 867
126 401
133 920
138 82
141 386
158 528
168 65
184 660
191 650
198 13
208 537
219 730
224 524
227 527
230 957
233 955
236 954
253 89
253 917
258 964
263 836
275 478
285 622
289 240
292 418
295 747
297 748
297 946
299 782
311 395
317 777
318 105
322 166
326 792
355 927
360 103
372 853
384 110
387 534
387 574
391 421
398 579
404 702
419 324
422 323
424 374
425 908
435 101
443 30
464 761
468 899
470 897
471 494
475 754
488 888
496 707
496 799
505 565
506 567
513 551
517 878
523 531
528 460
542 187
555 210
558 449
572 404
576 403
577 597
583 397
588 711
592 245
595 873
596 83
621 4
621 900
627 692
650 559
654 558
656 870
663 83
665 444
665 665
666 412
669 155
669 552
672 361
673 359
673 485
680 660
685 486
694 352
695 711
698 650
709 231
712 624
728 435
731 891
732 309
733 81
737 421
737 425
742 53
743 51
746 839
747 842
752 347
753 84
755 879
771 9
776 328
778 395
829 338
829 340
836 333
853 324
863 370
913 581
917 644
926 455
936 396
943 741
949 609
949 620
954 332
959 169
966 329
967 327
972 725
Geoff Hayes
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
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');

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by