Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
x1=magic(5);
x2=3;
x3=9;
[R1,C1]=RCMatrixIndices(x1,x2,x3);
[fr1,fc1]=find(and(x1>=x2,x1<x3));
assert(and(isequal(R1,fr1),isequal(C1,fc1)))
ind =
5×5 logical array
0 0 0 1 0
0 1 1 0 0
1 1 0 0 0
0 0 0 0 1
0 0 0 0 0
R =
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
C =
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
R =
3
2
3
2
1
4
C =
1
2
2
3
4
5
|
2 | Pass |
filetext = fileread('RCMatrixIndices.m');
assert(isempty(strfind(filetext, 'find')))
|
3 | Pass |
filetext = fileread('RCMatrixIndices.m');
assert(isempty(strfind(filetext, 'regexp')))
|
4 | Pass |
x1=magic(5);
x2=3;
x3=9;
[R2,C2]=RCMatrixIndices(x2,x1, x3);
[fr1,fc1]=find(and(x1>=x2,x1<x3));
assert(and(isequal(R2,fr1),isequal(C2,fc1)))
ind =
5×5 logical array
0 0 0 1 0
0 1 1 0 0
1 1 0 0 0
0 0 0 0 1
0 0 0 0 0
R =
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
C =
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
R =
3
2
3
2
1
4
C =
1
2
2
3
4
5
|
5 | Pass |
x1=magic(5);
x2=3;
x3=9;
[R3,C3]=RCMatrixIndices(x1,x3,x2);
[fr1,fc1]=find(and(x1>=x2,x1<x3));
assert(and(isequal(R3,fr1),isequal(C3,fc1)))
ind =
5×5 logical array
0 0 0 1 0
0 1 1 0 0
1 1 0 0 0
0 0 0 0 1
0 0 0 0 0
R =
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
C =
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
R =
3
2
3
2
1
4
C =
1
2
2
3
4
5
|
6 | Pass |
A=...
[3 3 3 3;...
8 3 3 3;...
8 8 3 3;...
8 8 8 3];
lowlim=3;
uplim=9;
[R4,C4]=RCMatrixIndices(A,uplim,lowlim);
assert(length(A(4*(C4-1)+R4))==16)
ind =
4×4 logical array
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
R =
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
C =
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
R =
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
C =
1
1
1
1
2
2
2
2
3
3
3
3
4
4
4
4
|
7 | Pass |
A=...
[3 3 3 3;...
8 3 3 3;...
8 8 3 3;...
8 8 8 3];
lowlim=4;
uplim=9;
%extract only 8
[R5,C5]=RCMatrixIndices(A,uplim,lowlim);
assert(all(A(4*(C5-1)+R5)==8))
ind =
4×4 logical array
0 0 0 0
1 0 0 0
1 1 0 0
1 1 1 0
R =
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
C =
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
R =
2
3
4
3
4
4
C =
1
1
1
2
2
3
|
8 | Pass |
A=...
[3 3 3 3;...
8 3 3 3;...
8 8 3 3;...
8 8 8 3];
lowlim=4;
uplim=7;
[R6,C6]=RCMatrixIndices(A,uplim,lowlim);
assert(and(isempty(R6),isempty(C6)))
ind =
4×4 logical array
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
R =
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
C =
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
R =
0×1 empty double column vector
C =
0×1 empty double column vector
|
9 | Pass |
A=...
[3 3 3 3;...
8 3 3 3;...
8 8 3 3;...
8 8 8 3];
lowlim=2;
uplim=7;
[R7,C7]=RCMatrixIndices(A,uplim,lowlim);
assert(and(all(A(4*(C7-1)+R7)==3),length(R7==10)))
ind =
4×4 logical array
1 1 1 1
0 1 1 1
0 0 1 1
0 0 0 1
R =
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
C =
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
R =
1
1
2
1
2
3
1
2
3
4
C =
1
2
2
3
3
3
4
4
4
4
|
10 | Pass |
A=1;
lowlim=1;
uplim=1;
[R8,C8]=RCMatrixIndices(A,uplim,lowlim);
assert(and(isempty(R8),isempty(C8)))
ind =
logical
0
R =
1
C =
1
R =
[]
C =
[]
|
11 | Pass |
A=1;
lowlim=1;
uplim=2;
[R9,C9]=RCMatrixIndices(A,uplim,lowlim);
assert(and(R9==1,C9==1))
ind =
logical
1
R =
1
C =
1
R =
1
C =
1
|
962 Solvers
Replace NaNs with the number that appears to its left in the row.
2018 Solvers
250 Solvers
The sum of the numbers in the vector
426 Solvers
Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)
226 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!