Error using stem (line 43) X must be same length as Y.

Illustration
praveen sebastian - 2022-10-31T11:42:06+00:00
Question: Error using stem (line 43) X must be same length as Y.

close all; clear all; clc; fs=6000; t=0:0.001:.1; t1=0:1/fs:1; f1=200; f2=1000; f3=1500; f4=2500; xa1=2*sin(f1*pi*t); xa2=3*cos(f2*pi*t); xa3=.5*sin(f3*pi*t); xa4=sin(f4*pi*t); xa11=2*sin(f1*pi*t); xa22=3*cos(f2*pi*t); xa33=.5*sin(f3*pi*t); xa44=sin(f4*pi*t); xa=xa1-xa2-xa3+xa4; xaa=xa11-xa22-xa33+xa44; subplot(2,1,1); plot(t,xa); ylabel('Amplitude'); xlabel('time t') title('original wave') hold on; subplot(2,1,2); stem(t1,xaa); ylabel('Amplitude'); xlabel('time t') title('Wave sampled at Fs=6000') hold on;  

Expert Answer

Profile picture of Neeta Dsouza Neeta Dsouza answered . 2025-11-20

xaa is an 1x101 array and t1 is 1x6001 array.
Put t1 instead of t when you define xa11,xa22,xa33,xa44
 
 
xa11=2*sin(f1*pi*t1);   
xa22=3*cos(f2*pi*t1);
xa33=.5*sin(f3*pi*t1);
xa44=sin(f4*pi*t1);

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!