Matlab新手求救,如何提高这段程序的运算效率m(1:115)=[1:115];fname=cell(115,1);M=zeros(321,528,115);Mean=zeros(1,115);stripeband=zeros(321,528,18);Nostripeband=zeros(321,528,97);stripebandmean=zeros(1,18);Nostripebandmean=zeros(1,97);up

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 07:44:26
Matlab新手求救,如何提高这段程序的运算效率m(1:115)=[1:115];fname=cell(115,1);M=zeros(321,528,115);Mean=zeros(1,115);stripeband=zeros(321,528,18);Nostripeband=zeros(321,528,97);stripebandmean=zeros(1,18);Nostripebandmean=zeros(1,97);up
xVKSV+r$6ؘMː颻LD~LgɌyX`px4 BH1FJ^ztbtYF;y<<1_!$7 6踝LViOg{0<4r\U5W4ǜ9߇E xRH^4-r~Q&bpNəYax9* Ì oGZ.&= eڢ&A{@ fiV%fuM}o,@D O7+(h!%D+ǀ.%>@3|E7-K5}UZ-hEׯaqaݸV^AxR8}}6 xmEp8ӮZ F=wRH-zaËlӔVN$͉KzVYj7ZK+Ts#^C,p22 4wSMqZuVhk7\HwbxmS, EJdu0<ƖGb / `WV h]|үTTlmiߴj-opFlY?C,׮2R7=@ԁȮo! ^س7槍s@HRg+75$iQ/s@:ḩ9w8|G5ZhwP eo3_,CP 0!E:AZ `S(eɼo/s_] q3"Q/Șn侙%L CVUkW ~_ַV'P1q`{*'u};myofk*u?ZVzO yGy]Ho滅|.UhD:tX3Ô-~J3f>l( X_

Matlab新手求救,如何提高这段程序的运算效率m(1:115)=[1:115];fname=cell(115,1);M=zeros(321,528,115);Mean=zeros(1,115);stripeband=zeros(321,528,18);Nostripeband=zeros(321,528,97);stripebandmean=zeros(1,18);Nostripebandmean=zeros(1,97);up
Matlab新手求救,如何提高这段程序的运算效率
m(1:115)=[1:115];
fname=cell(115,1);
M=zeros(321,528,115);
Mean=zeros(1,115);
stripeband=zeros(321,528,18);
Nostripeband=zeros(321,528,97);
stripebandmean=zeros(1,18);
Nostripebandmean=zeros(1,97);
upper1=zeros(321,528,1);
lower1=zeros(321,528,1);
upper2=zeros(321,528,97);
lower2=zeros(321,528,97);
upper=zeros(321,528,97);
upper2D=zeros(321,528);
lower12D=zeros(321,528);
upperall2D=zeros(321,528);
lower22D=zeros(321,528);
upper11=zeros(321,528,97);
lower11=zeros(1,1);
lower22=zeros(1,97);
upperall=zeros(1,97);
lowerall=zeros(1,97);
r=zeros(1,97);
jj=1;
kk=1;
for ii=1:length(m)
fname(ii)={strcat('波段',num2str(ii),'灰度图像')};
[K,mean]=Correlationcoefficient(char(fname(ii)));
M(:,:,ii)=K(200:520,112:639);
Mean(1,ii)=mean;
indicator(ii)=randindicator(char(fname(ii)));
if indicator(ii)>1.200000
stripeband(:,:,jj)=M(:,:,ii);
stripebandmean(1,jj)=Mean(1,ii);
jj=jj+1;
elseif indicator(ii)

Matlab新手求救,如何提高这段程序的运算效率m(1:115)=[1:115];fname=cell(115,1);M=zeros(321,528,115);Mean=zeros(1,115);stripeband=zeros(321,528,18);Nostripeband=zeros(321,528,97);stripebandmean=zeros(1,18);Nostripebandmean=zeros(1,97);up

我先就第一段for循环提点想法吧:

由于你的数据维度比较大,不太方便直接矩阵话操作,所以先保留循环;不过有可能的话,把stripeband等三维矩阵压缩二维(即把其中的每一个矩阵都展开成向量保存),会方便很多.毕竟,matlab是最擅长二维矩阵运算的.

cell矩阵的访问可以直接用花括号,比如fname{ii}

matlab现在已经对for循环做了优化,而索引(从矩阵里取数)的操作相对慢,所以一些中间变量(比如fname,Mean,M,indicator)其实没必要用矩阵把所有的都存下来,只要存当前循环中的值即可;

还有就是向量(1*N矩阵)不需要用二维索引.

我最后改成了这样

for ii=1:length(m)
    fname = sprintf('波段%d灰度图像', ii); % 取代strcat和str2num两次函数调用
    [K,mean]=Correlationcoefficient(fname);
    TMP=K(200:520,112:639);
    indicator = randindicator(fname);
    if indicator>1.200000
        stripeband(:,:,jj)=TMP;
        stripebandmean(jj)=mean;
        jj=jj+1;
    else %elseif indicator<=1.200000
        Nostripeband(:,:,kk)=TMP;
        Nostripebandmean(kk)=mean;
        kk=kk+1;
    end
end