用matlab 统计连续数值的个数
答案:3 悬赏:40
解决时间 2021-01-30 16:49
- 提问者网友:℡她的他i☆
- 2021-01-29 20:30
我要用matlab统计一串连续的数列中连续的大于某个值的数的个数,举例:假设有数列1004571123214507778155555555568,而我要统计大于4的连续树的个数,如遇到等于或小于4则重新统计。急用!谢谢
最佳答案
- 二级知识专家网友:伤口狠精致
- 2021-01-29 20:51
function p=temp(a,num)
if nargin~=2
error('参数个数不对???');
end
count=size(a);
count=count(2);
index=1;
i=1;
p=0;
while i<=count
if(a(i)>num+'0')
p(index)=p(index)+1;
else
if (p(index)==0)
i=i+1;
continue;
else
index=index+1;
p(index)=0;
end
end
i=i+1;
end
然后在command window中输入如:
>> a='1004571123214507778155555555568';
>> num=4;
>> temp(a,num)
ans =
2 1 4 11
if nargin~=2
error('参数个数不对???');
end
count=size(a);
count=count(2);
index=1;
i=1;
p=0;
while i<=count
if(a(i)>num+'0')
p(index)=p(index)+1;
else
if (p(index)==0)
i=i+1;
continue;
else
index=index+1;
p(index)=0;
end
end
i=i+1;
end
然后在command window中输入如:
>> a='1004571123214507778155555555568';
>> num=4;
>> temp(a,num)
ans =
2 1 4 11
全部回答
- 1楼网友:陪衬角色
- 2021-01-29 21:49
还是不太懂
- 2楼网友:年轻没有失败
- 2021-01-29 21:10
function p=temp(a,num)
if nargin~=2
error('参数个数不对???');
end
count=size(a);
count=count(2);
index=1;
i=1;
p=0;
while i<=count
if(a(i)>num+'0')
p(index)=p(index)+1;
else
if (p(index)==0)
i=i+1;
continue;
else
index=index+1;
p(index)=0;
end
end
i=i+1;
end
然后在command window中输入如:
>> a='1004571123214507778155555555568';
>> num=4;
>> temp(a,num)
ans =
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |