필터 지우기
필터 지우기

How to check an array for its content?

조회 수: 2 (최근 30일)
Philipp Mueller
Philipp Mueller 2020년 5월 26일
편집: Tommy 2020년 5월 26일
Hello,
I would like to query the contents of my array (the name is loadp - 40 * 1 double) if the value of each cell is not 0 or empty or NaN or whether the value has not already occurred in the previous runs by using the for loop. If this conditions are all true then set hello=1;
Thank you.
for i=1:numRows;
%tmp = regexp(my_strings(i),'(?<=_l)\d+','match','once');
loadp(i,1) = str2double(tmp)/100;%
if ~ismember(loadp(i),loadp(1:i-1)) ==1 && loadp(i)~=0 && (isnan(loadp(i,1))~=0 | isempty(loadp(i,1))~=0)
hello=1;
end
end

답변 (1개)

Tommy
Tommy 2020년 5월 26일
편집: Tommy 2020년 5월 26일
It sounds like you want to make sure isnan and isempty do return 0. Also, there is no need to explicitly check if the result of each of these operations is equal to true or false, as true==1 is the same as true and false==1 is the same as false.
for i=1:10
%tmp = regexp(my_strings(i),'(?<=_l)\d+','match','once');
loadp(i) = randi(10);
if ~ismember(loadp(i),loadp(1:i-1)) && loadp(i) && ~isnan(loadp(i)) && ~isempty(loadp(i))
hello=1;
end
end

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by