how to change the number that decreases in the array element to the same number, for example 0 (zero)
조회 수: 1 (최근 30일)
이전 댓글 표시
hello everyone,
I have an array element value as in the following code and this number will keep decreasing to about 10e-6, there should be a lot up to (1x500) but I just gave a few examples with this,
is there an easy way to change it to the same number eg 0 (zero)?
So in general it is not if it is worth below 1, for example, then it is zero, not like that, but if it is worth decreasing
Thank you very much
a = [100.001469926008 0.0140073495254864 0.00452326089811489 0.00228582409151486 0.00157249586126199 0.00121055360392781 0.000988328854777707 0.000836846113296335 0.000726496714817108]
if %there are array elements that are keep decreasing
%then everything changes to 0 so it remains (1x500) but everything is 0
end
댓글 수: 0
답변 (1개)
per isakson
2021년 1월 19일
편집: per isakson
2021년 1월 19일
Is something like this what you are asking for?
%%
a = [100.001469926008 0.0140073495254864 0.00452326089811489 ...
, 0.00228582409151486 0.00157249586126199 0.00121055360392781 ...
, 0.000988328854777707 0.000836846113296335 0.000726496714817108 ];
%%
daff = diff(a);
ix = find( a<1, 1, 'first' ); % "worth below 1"
if all( daff(ix:end) < 0 ) % "keep decreasing"
a(ix:end)=0; % "changes to 0"
end
it returns
>> a
a =
Columns 1 through 5
100 0 0 0 0
Columns 6 through 9
0 0 0 0
Based on the comments below I think the best answer is:
%%
daff = diff(a);
if all( daff < 0 ) % "keep decreasing" monotonically decreasing
a(:) = 0; % "changes to 0" "(:)" is needed to replace ALL values by 0
end
댓글 수: 14
per isakson
2021년 1월 19일
"I have been asking this for a long time about 2 weeks ago"
- how to change the number that decreases in the array element to the same number, for example 0 (zero) (this question) 1 answer, 12 comments
- findpeaks [pks, locs] cannot detect NaN 1 answer, 9 comments (Walter Roberson explained why the statement, if u ~= 0, is wrong in the context. Nevertheless, it appears in a code of one of your comments of this question.)
- how to make nan turn into 0 in array 0 answers, 22 comments
- and a couple of more questions, which are on related problems
Several people have put a fair amount of effort into helping you. They haven't contributed to answer this question. I guess, you lost them.
"because maybe what is in Matlab is different from what is in Simulink"
Communication is difficult. What does this paragraph say?
"have changed my simulink to r2018b"
I've run your model and browsed the diagnostics. It's above my head to debug this model.
See my addendum to the answer.
참고 항목
카테고리
Help Center 및 File Exchange에서 Array Geometries and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!