Vectors must be the same length.
古いコメントを表示
%Signal generator code
disp('Welcome to our signal generation simple application')
sf= input('Please enter sampling frequency:');%sampling frequency
start= input('Please enter signal start point:');%start point
ending= input('Please enter signal end point:');%end point %end is a key word so we couldn't use it as a variable
bp= input('Please enter number of break points');%break points
bpvec=zeros(1,bp);%breaking points vector
if bp~=0
t=linspace(start,ending,(ending-start)*sf);
for i=1:1:bp
bpvec(i)=input('please enter the position of the breaking point');
t1=linspace(start,bpvec(i),(bpvec(i)-start)*sf);
type= menu('type of the sigal partition','Impulse signal','DC signal','Ramp signal','Exponential','Sinusoidal');%type of each partition
switch type
case 1
area=input('please enter the area');
x=zeros(1,length(t1));
x(1)=area;
y1=x;
case 2
amp=input('please enter the amplitude');
x=amp*(ones(1,length(t1)));
y1=x;
case 3
slope=input('please enter the slope');
intercept=input('please enter the intercept');
y1=slope*t1+intercept;
case 4
amp=input('please enter the amplitude');
ex=input('please enter the exponent');
y1=amp*exp(t1*ex);
case 5
amp=input('please enter the amp');
freq=input('please enter the frequency');
phase=input('please enter the phase');
y1=amp*sin((2*pi*freq*t1)+phase);
end
start=bpvec(i);
if i==1
y=y1;
else
y=[y y1];
end
y=[y y1];
end
else %if no break points
t=linspace(start,ending,(ending-start)*sf);
type= menu('Impulse signal','DC signal','Ramp signal','Exponential','Sinusoidal');%type of each partition
switch type
case 1
area=input('please enter the area');
x=zeros(1,length(t));
x(1)=area;
y1=x;
case 2
amp=input('please enter the amplitude');
x=amp.*(ones(1,length(t)));
y1=x;
case 3
slope=input('please enter the slope');
inttercept=input('please enter the intercept');
y1=slope*t+intercept;
case 4
amp=input('please enter the amplitude');
ex=input('please enter the exponent');
y1=amp*exp(t*ex);
case 5
amp=input('please enter the amp');
freq=input('please enter the frequency');
phase=input('please enter the phase');
y1=amp*sin((2*pi*freq*t)+phase);
end
y=y1;
end
plot(t,y)
3 件のコメント
Walter Roberson
2018 年 11 月 23 日
please show the complete error message
youssif wahdan
2018 年 11 月 23 日
Walter Roberson
2018 年 11 月 24 日
what is the
sequence of inputs that trigger the error?
回答 (2 件)
madhan ravi
2018 年 11 月 24 日
plot(t,y(1:numel(t)))
%or
plot(t(1:numel(y)),y)
Walter Roberson
2018 年 11 月 24 日
You have
if i==1
y=y1;
else
y=[y y1];
end
y=[y y1];
Every iteration of the for i loop, that adds y1 to the end of y twice, so y will be length 2*bp . But you have
t=linspace(start,ending,(ending-start)*sf);
which is a length that is unrelated to bp.
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!