필터 지우기
필터 지우기

Find the elements in matrix that are not within the specified range

조회 수: 2 (최근 30일)
Yesbol
Yesbol 2017년 6월 1일
답변: Andrei Bobrov 2017년 6월 2일
Hello all,
This is question is the extension of this question.
The solution provided by dpb is shown below:
lo=207; hi=253; % set the limits desired
ix=iswithin(loads,lo,hi); % check all are ok, ix is logical array of locations
isOK=all(ix); % if T, all are ok for each column
if all(isOK)
fprintf('All is well\n')
else
bad=sum(~isOK); % number failed columns (loads)
fmt=['Load %2d' repmat(', %2d',1,bad-1) '\n'] % format string to print offending load(s)
fprintf(fmt,find(~isOK)) % and print the message
fprintf('Total number of loads failed: %d\n',bad) % and the total
end
iswithin is a utility function of dpb
type iswithin
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
The program needs to be modified in the following way. I have a matrix 288x55. I need to find the elements in matrix that are not within the specified range. Unlike the question above (program returned true if only one element is not within the specified range), this program should return true only if two elements one after another in a matrix are not within the range.
Note that program needs to return true only if elements are one after another.
The limits are 207 and 253.
For example, if a given matrix is:
232 209 237
241 226 233
237 229 235
205 215 205
227 227 219
227 240 227
242 221 238
245 205 234
217 218 229
218 233 204
232 221 213
230 241 246
232 223 232
217 233 230
214 223 226
229 238 *265*
245 210 *262*
238 250 228
229 227 236
225 228 246
216 213 228
241 230 242
240 229 242
228 215 233
235 237 214
233 *254* 240
241 *255* 231
254 229 249
Then isOK should return 0 1 1
Any help is greatly appreciated.
Please feel free to ask questions if the problem needs some clarification.
Thank you
  댓글 수: 3
dpb
dpb 2017년 6월 2일
"this program should return true only if two elements one after another in a matrix are not within the range."
Two and only two more than one?
Also, what's the definition of "elements one after another in a matrix", precisely? In memory order, column order, row order, does count start over at each column/row...?
Yesbol
Yesbol 2017년 6월 2일
Thank you for your comment, dpb. Sorry I did not make it clear. I made some modifications. Hope it will clarify.

댓글을 달려면 로그인하십시오.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2017년 6월 2일
a = [232 209 237
241 226 233
237 229 235
205 215 205
227 227 219
227 240 227
242 221 238
245 205 234
217 218 229
218 233 204
232 221 213
230 241 246
232 223 232
217 233 230
214 223 226
229 238 265
245 210 262
238 250 228
229 227 236
225 228 246
216 213 228
241 230 242
240 229 242
228 215 233
235 237 214
233 254 240
241 255 231
254 229 249];
n = size(a,2);
t = a < 207 | a > 250;
k = cumsum([false(1,n);diff(t) == 1]).*t;
out = any(histc(k,1:max(k(:)+1)) >= 2);

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by