Need help to calculate this
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hello.
First of all, I have binary array, for example f = (1, 1, 1, 1, 0, 0, 0, 0). In my array there is no numbers lined up like this f = (1,0,1,1,0,1).
This is my code:
kiek = 0;
taskas = 0;
tarpas = 0;
bruksnys = 0;
for i = 2:length(f)
if f(i-1) == 1 && f(i) ~= 0
kiek = kiek + 1;
if kiek == 3000
taskas = taskas + 1;
end
if kiek == 13000
bruksnys = bruksnys + 1;
end
end
if f(i) == 0
kiek = 0;
end
end
When I run the code I get aswers like this:
bruksnys = 4
taskas = 15
The problem is that I have to get answer:
bruksnys = 4
taskas = 11
It's allways add up but I don't know how provent from this
Can somebody help me.
댓글 수: 4
John D'Errico
2020년 3월 21일
Incredibly confusing. You have an array like?
f = (1, 1, 1, 1, 0, 0, 0, 0)
First, that is not an array. This is an array:
f = [1, 1, 1, 1, 0, 0, 0, 0]
Ok, a minor point, and sort of irrlevant. But if you want to use MATLAB, then learn to use MATLAB.
But now you say you have no numbers "lined up"? What does lined up mean to you? You give an example of a vector where it is not obvious why that vector is different from what you showed first.
Ok, maybe I can look at your code. But that is even more confusing.
kiek = 0;
So kiek is a SCALAR variable. In fact, nothing you do to it makes kiek into a vector or array. But how do you use it? You test the RANGE of kiek. Seriously?
In MATLAB, the function range applies to a vector or array. It computes the maximum of the vector, and subtracts the minimum. As such, range, when applied to a scalar variable, will ALWAYS return 0. For example:
range(12)
ans =
0
Now, again, how do you use it?
if range(kiek) == 3000
Yup, you perform a test that ALWAYS returns false. Not sure why, but you do.
darova
2020년 3월 21일
Where is the mistake?
Ricardas Gudonavicius
2020년 3월 21일
편집: Ricardas Gudonavicius
2020년 3월 21일
Ricardas Gudonavicius
2020년 3월 21일
답변 (0개)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!