i dont know whats the problem with this fails with variable test
1 回表示 (過去 30 日間)
古いコメントを表示
function [summa index]=max_sum(v,n)
m=zeros(1,length(v));
x=zeros(1,length(v));
j=1;
if n>length(v)
summa=0;
index=-1;
elseif n<length(v)
for ii=1:length(v)
if ii<=length(v)-n+1
x=v(:,ii:n+ii-1);
m(ii)=sum(x);
else
x=v(:,ii:length(v));
z=v(:,1:j);
m(ii)=sum(x)+sum(z);
j=j+1;
end
end
[y i]=max(m);
summa=max(y);
index=max(i);
else
summa=sum(v);
index=1;
end
2 件のコメント
Mario Malic
2020 年 8 月 1 日
編集済み: Mario Malic
2020 年 8 月 1 日
We also don't know what's the problem. Could you tell us?
What is this?[summa index]
回答 (1 件)
Image Analyst
2020 年 8 月 1 日
編集済み: Image Analyst
2020 年 8 月 1 日
When you do
m(ii)=sum(x);
x is a 2-D array. So sum(x) is a 1-D array, because it's summing each column, and you're trying to put a whole array into a single element, the ii'th element of m. What do you intend to sum? The whole array? If so, do this:
m(ii)=sum(x(:));
6 件のコメント
Image Analyst
2020 年 8 月 2 日
I don't think you need the if and for loop. You can simply use movmean().
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!