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

praveen sebastian · Oct 31, 2022 · 2.2K views
Question
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 PhD Expert
Answered Aug 16, 2026
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);

 

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

Get a Free Consultation or a Sample Assignment Review!