当前位置:编程学习 > Matlab >>

【求代码】在matlab中,记录一个一维数组中数字有0变为1的次数,且记录下变化的位置。

例如记录数组t=[0 0 0 1 2 2 3 0 0 1 0 1 2 2 0 01]中数字由0变为1的位置。
补充:最好用循环语句的形式,谢谢!
答案:t=[0 0 0 1 2 2 3 0 0 1 0 1 2 2 0 01]
findstr(t,[0 1]) 
_________

t=[0 0 0 1 2 2 3 0 0 1 0 1 2 2 0 01]
k=0;idx=[];
for n=1:length(t)-1
if t(n:n+1)==[0 1]
k=k+1;idx=[idx,n];
end
end
k%数目
idx%位置
其他:1 是这个意思么?    
        int[] a=new int[]{0,0,0,1,2,2,3,0,0,1,0,1,2,2,0,0,1};
        string index = string.Empty;
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i].ToString() == "1")
                if (index.Length == 0)
                    index = i.ToString();
                else
                    index += "," + i.ToString();
        }
        Response.Write(index); 

上一个:【紧急】matlab 代码错误
下一个:请高手帮助求解Matlab最优化问题- 极值问题- Monte Carlo方法。希望得到你的答案以及代码,急!不胜感激!

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,