Question
So I have a .wav file and I need to plot 5000 time samples of it. The .wav file is sampled at 44.1 kHz (which would be my fs). I initially was able to plot my signal, but then realized I needed to do it over 5000 samples. I tried doing it, but would get the error "Vectors must be the same length" when I go to plot. Original Code [x,fs]=audioread('Song.wav'); t=linspace(0,length(x)/fs,length(x)); plot(t,x) xlabel('time') ylabel('x[n]') New Code (which I thought I would only need to change my linspace, but it doesn't seem to like it) n = 5000; [x,fs]=audioread('Song.wav'); t=linspace(0,length(x)/fs,n); plot(t,x) xlabel('time') ylabel('x[n]') Appreciate any help/guidance!
Expert Answer
Neeta Dsouza
PhD Expert
Answered Aug 25, 2026
n = 5000;
[x,fs]=audioread('Song.wav');
idx = 1:n;
subset = x(idx,:);
t = (idx-1)./fs;
plot(t,subset)
xlabel('time')
ylabel('x[n]')
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related digital signal pro.... Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →