matlab中Index exceeds matrix dimensionsclear; close all; clc;load data0.matx=b(:,1);y=b(:,2);n1=17; %中值滤波窗口n2=15;y1 =[y;y(1:n1)];[m,n] = size(y);out =[];s = [];for i=1:m*ns=sort(y1(i:i+n1-1));out(i)=mean(s(i+1:i+n1-2));endy2=out;subplot(
来源:学生作业帮助网 编辑:六六作业网 时间:2025/02/02 13:48:00
matlab中Index exceeds matrix dimensionsclear; close all; clc;load data0.matx=b(:,1);y=b(:,2);n1=17; %中值滤波窗口n2=15;y1 =[y;y(1:n1)];[m,n] = size(y);out =[];s = [];for i=1:m*ns=sort(y1(i:i+n1-1));out(i)=mean(s(i+1:i+n1-2));endy2=out;subplot(
matlab中Index exceeds matrix dimensions
clear; close all; clc;
load data0.mat
x=b(:,1);
y=b(:,2);
n1=17; %中值滤波窗口
n2=15;
y1 =[y;y(1:n1)];
[m,n] = size(y);
out =[];
s = [];
for i=1:m*n
s=sort(y1(i:i+n1-1));
out(i)=mean(s(i+1:i+n1-2));
end
y2=out;
subplot(2,2,1);
plot(x,y);
xlabel('t/s');ylabel('电压幅值/v');
title('滤波前波形');
subplot(2,2,2);
plot(x,y2);
xlabel('t/s');ylabel('电压幅值/v');
title('中位平均滤波');
axis([-0.05 0.05,2.2,3.2]);
grid on;
程序中data0为一个含有2500个数据的数组,
其中报错如下:
Index exceeds matrix dimensions.
Error in ==> middlefilter at 13
out(i)=mean(s(i+1:i+n1-2));
谁知道为什么吗,怎么修改
matlab中Index exceeds matrix dimensionsclear; close all; clc;load data0.matx=b(:,1);y=b(:,2);n1=17; %中值滤波窗口n2=15;y1 =[y;y(1:n1)];[m,n] = size(y);out =[];s = [];for i=1:m*ns=sort(y1(i:i+n1-1));out(i)=mean(s(i+1:i+n1-2));endy2=out;subplot(
试着写了一个,LZ试试看行不行:
clear
clc
x = 1:2500;
y = randn(1,2500);
n=17; %中值滤波窗口
for i = 1:length(y)-n+1
yy = y(i:i+n-1);
out(i) = mean(yy(~((yy == min(yy))|(yy == max(yy)))));
end
subplot(2,1,1);
plot(x,y);
subplot(2,1,2);
outx = x(1:length(y)-n+1);
plot(outx,out);