function [p3 min1 max1 min2 max2]=maxProfit(prices,n)
temp1 = 0;
temp2 = 0;
temp3 = 0;
 l = 0;
 p1 = 1;
 p2 = 1;
 p3 = 1;
 maxa1 =  0;
 maxa2 = 0 ;
 mina1 = 0;
 mina2 =0;
 max1 =  0;
 max2 = 0 ;
 min1 = 0;
 min2 =0;


while(l<n)
    for i=1:l
        for j=i+1:l
            if prices(j)-prices(i)>temp1
                temp1 = prices(j)-prices(i);
                p1 = prices(j)/prices(i);
                maxa1 = j;
                mina1 = i;
            end
            
        end
    end
    for i=l+1:n
        for j=i+1:n
            if prices(j)-prices(i)>temp2
                temp2 = prices(j)-prices(i);
                p2 = prices(j)/prices(i);
                maxa2 = j;
                mina2 = i;
            end
            
        end
    end
    if p1*p2>p3
        p3 = p1*p2;
        max1 = maxa1;
        max2 = maxa2;
        min1 = mina1;
        min2 = mina2;
        
    end
    temp2 = 0 ;
    temp1 = 0;
    p1 = 1;
    p2 = 1;
    l = l+1 ;
      
end
end




导入表格数据报错如下:

>> [p3 min1 max1 min2 max2]=maxProfit(testa,1530)
错误使用 maxProfit (line 22)
不能使用线性索引(一个下标)或多维索引(三个或更多下标)来给表添加下标。请使用行下标和变
量下标。