% function [B]=SNV(A)
clc;
% A=data';
Waveband=[918.599976 921.580383 924.560791 927.541199 930.521606 933.502014 936.482422 939.46283 942.443176 945.423584 948.403992 951.384399 954.364807 957.345215 960.325623 963.30603 966.286377 969.266785 972.247192 975.2276 978.208008 981.188416 984.168823 987.14917 990.129578 993.109985 996.090393 999.070801 1002.051208 1005.031616 1008.012024 1010.992371 1013.972778 1016.953186 1019.933594 1022.914001 1025.894409 1028.874756 1031.855225 1034.835571 1037.81604 1040.796387 1043.776855 1046.757202 1049.737549 1052.718018 1055.698364 1058.678833 1061.65918 1064.639648 1067.619995 1070.600342 1073.580811 1076.561157 1079.541626 1082.521973 1085.502441 1088.482788 1091.463257 1094.443604 1097.42395 1100.404419 1103.384766 1106.365234 1109.345581 1112.32605 1115.306396 1118.286743 1121.267212 1124.247559 1127.228027 1130.208374 1133.188843 1136.169189 1139.149658 1142.130005 1145.110352 1148.09082 1151.071167 1154.051636 1157.031982 1160.012451 1162.992798 1165.973145 1168.953613 1171.93396 1174.914429 1177.894775 1180.875244 1183.855591 1186.83606 1189.816406 1192.796753 1195.777222 1198.757568 1201.738037 1204.718384 1207.698853 1210.679199 1213.659546 1216.640015 1219.620361 1222.60083 1225.581177 1228.561646 1231.541992 1234.522461 1237.502808 1240.483154 1243.463623 1246.44397 1249.424438 1252.404785 1255.385254 1258.365601 1261.345947 1264.326416 1267.306763 1270.287231 1273.267578 1276.248047 1279.228394 1282.20874 1285.189209 1288.169556 1291.150024 1294.130371 1297.11084 1300.091187 1303.071655 1306.052002 1309.032349 1312.012817 1314.993164 1317.973633 1320.953979 1323.934448 1326.914795 1329.895142 1332.87561 1335.855957 1338.836426 1341.816772 1344.797241 1347.777588 1350.758057 1353.738403 1356.71875 1359.699219 1362.679565 1365.660034 1368.640381 1371.62085 1374.601196 1377.581543 1380.562012 1383.542358 1386.522827 1389.503174 1392.483643 1395.463989 1398.444458 1401.424805 1404.405151 1407.38562 1410.365967 1413.346436 1416.326782 1419.307251 1422.287598 1425.267944 1428.248413 1431.22876 1434.209229 1437.189575 1440.170044 1443.150391 1446.130859 1449.111206 1452.091553 1455.072021 1458.052368 1461.032837 1464.013184 1466.993652 1469.973999 1472.954346 1475.934814 1478.915161 1481.89563 1484.875977 1487.856445 1490.836792 1493.817261 1496.797607 1499.777954 1502.758423 1505.73877 1508.719238 1511.699585 1514.680054 1517.6604 1520.640747 1523.621216 1526.601563 1529.582031 1532.562378 1535.542847 1538.523193 1541.50354 1544.484009 1547.464355 1550.444824 1553.425171 1556.40564 1559.385986 1562.366455 1565.346802 1568.327148 1571.307617 1574.287964 1577.268433 1580.248779 1583.229248 1586.209595 1589.189941 1592.17041 1595.150757 1598.131226 1601.111572 1604.092041 1607.072388 1610.052856 1613.033203 1616.01355 1618.994019 1621.974365 1624.954834 1627.935181 1630.915649 1633.895996 1636.876343 1639.856812 1642.837158 1645.817627 1648.797974 1651.778442 1654.758789 1657.739258 1660.719604 1663.699951 1666.68042 1669.660767 1672.641235 1675.621582 ];%1678.602051
%]';
% Waveband=Waveband';
[data_m,data_n]=size(A);
B=zeros(data_m,data_n);
C=zeros(data_m,data_n);
for i=1:data_m
for j=1:data_n
B(i,j)=(A(i,j)-mean(A(i,:),2))/std(A(i,:));
% B(i,j)=A(i,j)-mean(A(i,:)*ones(1,j))./(std(A(i,:))*ones(1,j));
% xsnv=(x-mean(x')'*ones(1,n))./(std(x')'*ones(1,n));
end
end
% C(i,j)=C(i,j)+B(i,j);
% plot(Waveband,B);
plot(1:256,B);
% axis([900,1700,-0.9,0.9])
title('SNV预处理图','FontSize',14);
xlabel('波 长/nm','FontSize',14);
ylabel('反 射 率','FontSize',14);
% box off
clc;
x=data;
[m,n]=size(x);
rmean=mean(x,2);
dr=x-repmat(rmean,1,n);
x_snv=dr./repmat(sqrt(sum(dr.^2,2)/(n-1)),1,n);
plot(1:256,x_snv);
% axis([900,1700,-0.9,0.9])
xlabel('波 长/nm','FontSize',14);
ylabel('反 射 率','FontSize',14);
box off