我有一个脚本可以执行以下操作:我有一个Excel电子表格,其中包含三列叶绿素浓度,有时甚至更多。例如。 1)WholeFluro 2)WholeHPLC 3)Net1Fluro但不是所有三列都具有所有3个数据集。例如,我经常使用WholeFluro和WholeHPLC或者只有Net1Fluro。为了获得更多数据,我喜欢将所有数据合并到一个数据列中。此外,我还在海洋中有相应的位置,我从中收集了数据,以及我抽样样本的水柱深度。
我有一个MATLAB脚本,我用它,但它很长,我需要很长时间才能将它用于我想要合并的不同类型的数据。我想知道我是否可以获得一些帮助以提高效率,因为它还可以帮助我学习编写更好的脚本。
我的脚本如下:
% go to the data folder
cd C:\Users\Documents\CHLOROPHYLL_DATA_PROCESSED\
filename = 'Knorr-Working_SizeFracNew.xlsx';
[num,txt,raw] = xlsread(filename);
% Pick out the relevant data that you need from the large spreadsheet
%Use Raw only to get header info because I can see the header info that I %cannot see in ‘num’
% Use ‘num’ to get actual data
FracsData=num(:,[1:2:7 8:2:17 19:23 24 29 34]);
FracsHeaderInfo=raw(:,[1:2:7 8:2:17 19:23 24 29 34]);
%%
% choose the various Chlorophyll data from the large spreadsheet that I want %to merge
% Here I want to Merge the two columns which have Whole, two columns with
% Net1, two columns with % Net2 and two columns with Net3
WholeFluro=FracsData(:,6);
WholeHPLC=FracsData(:,10);
Net1Fluro=FracsData(:,7);
Net1HPLC=FracsData(:,15);
Net2Fluro=FracsData(:,8);
Net2HPLC=FracsData(:,16);
Net3Fluro=FracsData(:,9);
Net3HPLC=FracsData(:,17);
%%
%Replace NaNs with -999 or I get an error when NaNs from various columns %clash
WholeFluro(isnan(WholeFluro))=-999;
WholeHPLC(isnan(WholeHPLC))=-999;
Net1Fluro(isnan(Net1Fluro))=-999;
Net1HPLC(isnan(Net1HPLC))=-999;
Net2Fluro(isnan(Net2Fluro))=-999;
Net2HPLC(isnan(Net2HPLC))=-999;
Net3Fluro(isnan(Net3Fluro))=-999;
Net3HPLC(isnan(Net3HPLC))=-999;
% Here I create 4 variables that will hold my merged data for whole, N1, N2, % & N3 that are equal to the % the original data
MergedDataWhole = WholeFluro;
MergedDataN1 = Net1Fluro;
MergedDataN2 = Net2Fluro;
MergedDataN3 = Net3Fluro;
%find the empty places and fill them up with the HPLC data at points x – I %give HPLC data precedence
x=find(MergedDataWhole==-999);
MergedDataWhole(x)=WholeHPLC(x);
x=find(MergedDataN1==-999);
MergedDataN1(x)=Net1HPLC(x);
x=find(MergedDataN2==-999);
MergedDataN2(x)=Net2HPLC(x);
x=find(MergedDataN3==-999);
MergedDataN3(x)=Net3HPLC(x);
MergedDataALL=horzcat(MergedDataWhole,MergedDataN1,MergedDataN2,MergedDataN3);
MergedDataALL(MergedDataFracs<0)=0;
outputfilename = 'Merged.xlsx';
[suc,msg] = xlswrite(outputfilename,Merged);