problem with m file

2 views (last 30 days)
Sadiq Akbar
Sadiq Akbar on 30 Sep 2020
Commented: Steven Lord on 30 Sep 2020
I have written the following m file, but gives me error instead of plotting the data. The error I get is:Error using plot
Vectors must be the same length.
Error in NAEAllSources (line 522)
plot(t,smooth(data),'linewidth',2). Code is given below:
NE2sn0=[0.E+00
3.E+00
0.E+00
3.E-04
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
3.E+00
7.E-05
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
3.E-05
3.E+00
0.E+00
0.E+00
5.E-06
0.E+00
0.E+00
0.E+00
3.E-05
2.E+00
0.E+00
8.E-11
0.E+00
0.E+00
0.E+00
3.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
9.E-09
3.E-05
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
1.E-06
4.E-04
1.E-06
0.E+00
2.E-04
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
1.E-04
0.E+00
0.E+00
0.E+00
3.E+00
0.E+00
0.E+00
0.E+00
0.E+00
3.E-05
0.E+00
0.E+00
4.E-05
0.E+00
3.E-15
0.E+00
4.E-05
6.E-04
0.E+00
0.E+00
];
% 35dB Noise
NE2sn35=[1.E-16
6.E-10
3.E+00
0.E+00
0.E+00
0.E+00
1.E-16
0.E+00
0.E+00
3.E-07
0.E+00
1.E-16
1.E-16
0.E+00
1.E-16
0.E+00
9.E-09
0.E+00
9.E-09
0.E+00
2.E-12
0.E+00
0.E+00
1.E-16
0.E+00
3.E-07
4.E-07
0.E+00
0.E+00
0.E+00
3.E+00
0.E+00
0.E+00
3.E-05
0.E+00
3.E-04
3.E+00
0.E+00
0.E+00
6.E-05
3.E+00
1.E-16
6.E-06
0.E+00
0.E+00
3.E+00
0.E+00
0.E+00
0.E+00
0.E+00
1.E-11
0.E+00
0.E+00
1.E-08
1.E-16
0.E+00
1.E-16
1.E-12
1.E-16
0.E+00
2.E-06
0.E+00
0.E+00
0.E+00
8.E-10
0.E+00
1.E-04
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
3.E+00
0.E+00
1.E-03
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
3.E+00
3.E-07
0.E+00
0.E+00
2.E-09
0.E+00
0.E+00
2.E-06
9.E-07
0.E+00
];
%45dB Noise
NE2sn45=[2.E+00
0.E+00
1.E-16
8.E-06
3.E+00
0.E+00
0.E+00
0.E+00
1.E-16
0.E+00
3.E-11
1.E-05
2.E+00
0.E+00
1.E-16
1.E-16
0.E+00
3.E-04
0.E+00
0.E+00
0.E+00
0.E+00
7.E-04
0.E+00
1.E-16
2.E-07
0.E+00
0.E+00
1.E-16
0.E+00
0.E+00
0.E+00
1.E-16
2.E-06
2.E-06
0.E+00
0.E+00
1.1102e-16
1.1102e-16
0.E+00
4.E-05
2.E-09
3.E+00
0.E+00
0.E+00
0.E+00
3.E+00
1.1102e-16
3.E-05
0.E+00
1.E-06
2.E-16
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
2.E-05
0.E+00
0.E+00
0.E+00
1.E-03
0.E+00
0.E+00
1.E-16
0.E+00
0.E+00
0.E+00
1.E-07
3.E-08
0.E+00
0.E+00
2.E-07
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
1.E-16
0.E+00
1.E-16
1.E-16
0.E+00
0.E+00
2.E-05
0.E+00
9.E-04
0.E+00
3.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
1.E-16
1.E-16
0.E+00
0.E+00
1.E-16
1.E-16
];
%55dB Noise
NE2sn55=[1.E-16
0.E+00
4.E-08
3.E-04
0.E+00
0.E+00
3.E+00
0.E+00
2.E-04
0.E+00
0.E+00
7.E-05
0.E+00
0.E+00
0.E+00
1.E-16
5.E-06
0.E+00
2.E-08
0.E+00
1.E-16
0.E+00
4.E-06
1.E-16
1.E-16
1.E-16
0.E+00
0.E+00
0.E+00
1.E-16
7.E-06
0.E+00
0.E+00
1.E-16
6.E-04
0.E+00
3.E-04
0.E+00
0.E+00
2.E-11
6.E-05
1.E-16
0.E+00
1.E-16
0.E+00
1.E-16
1.E-16
1.E-16
0.E+00
7.E-05
0.E+00
0.E+00
1.E-04
0.E+00
0.E+00
1.E-16
7.E-06
0.E+00
6.E-05
0.E+00
0.E+00
0.E+00
0.E+00
7.E-05
0.E+00
1.E-16
6.E-06
5.E-05
5.E-08
3.E-10
2.E-05
1.E-16
2.E-07
0.E+00
1.E-09
0.E+00
0.E+00
0.E+00
9.E-09
3.E+00
0.E+00
0.E+00
0.E+00
1.E-16
0.E+00
0.E+00
1.E-16
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
3.E-05
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
1.E-16
2.E-16
];
%65dB Noise
NE2sn65=[0.E+00
0.E+00
7.E-10
0.E+00
2.E-07
0.E+00
0.E+00
3.E-06
3.E+00
0.E+00
0.E+00
0.E+00
0.E+00
0.E+00
3.E-08
1.E-16
0.E+00
1.E-16
4.E-05
0.E+00
0.E+00
0.E+00
1.E-05
0.E+00
2.E-03
1.E-16
0.E+00
6.E-10
0.E+00
0.E+00
1.E-04
0.E+00
3.E+00
7.E-04
0.E+00
0.E+00
0.E+00
0.E+00
1.E-16
0.E+00
1.E-16
5.E-08
1.E-16
1.E-14
1.E-04
0.E+00
1.E-16
0.E+00
0.E+00
0.E+00
4.E-09
0.E+00
0.E+00
0.E+00
7.E-07
0.E+00
2.E-04
1.E-04
0.E+00
0.E+00
0.E+00
6.E-05
0.E+00
1.E-16
1.E-12
4.E-05
0.E+00
0.E+00
0.E+00
0.E+00
1.E-16
3.E+00
0.E+00
0.E+00
3.E+00
2.E-07
1.E-16
0.E+00
3.E+00
7.E-05
0.E+00
7.E-05
0.E+00
0.E+00
1.E-16
0.E+00
1.E-16
0.E+00
3.E+00
0.E+00
0.E+00
0.E+00
7.E-05
1.E-16
0.E+00
0.E+00
3.E+00
0.E+00
0.E+00
0.E+00
];
%Arranging in descending order
NE2sn0=sort(NE2sn0,'descend');
NE2sn35=sort(NE2sn35,'descend');
NE2sn45=sort(NE2sn45,'descend');
NE2sn55=sort(NE2sn55,'descend');
NE2sn65=sort(NE2sn65,'descend');
data=[NE2sn0;NE2sn35;NE2sn45;NE2sn55;NE2sn65]; % Combined all in 3x1 matrix
% Plotting
t=1:100;
plot(t,smooth(data),'linewidth',2)
% plot(t,smooth(NE2sn0),'linewidth',2,t,smooth(NE2sn35),'linewidth',2)

Answers (1)

Ameer Hamza
Ameer Hamza on 30 Sep 2020
The number of x and y values must be same. Change the time-vector to
t=1:numel(data);
  3 Comments
Steven Lord
Steven Lord on 30 Sep 2020
Or if you know your data is real and you want the X coordinates to be 1:numel(data) you can just call plot with one data input.
plot((1:10).^2, 'o-', 'LineWidth', 2) % Uses x = 1:10

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by