Error using vertcat Dimensions of arrays being concatenated are not consistent.

3 views (last 30 days)
The problem seems to be with array concatenation. I dont understand how can this be fixed as I am not very fluent in Matlab
%Clear and clc commands to avoid data overwrite or damage
clear;
clc;
%Reading the .wav mono audio file as a "vector"
[s, F] = audioread('audiofile1.m4a');
%Setting the amplitude of the coming echos
A=0.9;
%Setting the vaule of the delay
L = 0.8*F;
%Generating and adding the echo
s = [s; zeros(20*L,1)];
sn = zeros(length(s),1);
sn=s+(A.*circshift(s,L));
%Playing the new echoed audio
sound(sn,F);
%Plotting the original plot versus the new one of the audios
plot(s);
subplot(2,1,1);
plot(sn);
subplot(2,1,2);
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in (line 11)
s = [s; zeros(20*L,1)];
  4 Comments
Sindar
Sindar on 7 May 2020
Then you can only horizontally catenate objects of size 214976xN to it. Looking closer, it's unclear what you plan to do with that line, since L is only coincidentally an integer
This would add a column of zeros to s:
s = [s; zeros(size(s,1),1)];
Mahmoud Fadel
Mahmoud Fadel on 7 May 2020
I added this line but unfortunately it still isn't working
I tried another audio file and size(s) had only 1 column.
Could it be that audiofile1.wav isn't mono? if so, how can I read into s as such?

Sign in to comment.

Answers (1)

Mahesh Taparia
Mahesh Taparia on 11 May 2020
Hi
By looking at your code,
s = [s; zeros(20*L,1)];
you want to append the rows which consists of zeros. You have mentioned in the comments that the size of s is 214976X2. So the number of columns in appending rows should be 2, i.e it should be
s = [s; zeros(20*L,2)];

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!