Can anyone please tell me how to reduce this size?
You already use vectorized assignment. Carry that further and get rid of the for loop.
The functions sum() and prod() can reduce row-wise to bring out NaN values. Thus, this express produces logicals for whether each row is in or out...
~isnan(prod(A,2))
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
A = [ 1 5 8
-3 NaN 14
0 6 NaN ];
B_correct = [ 1 5 8 ];
assert(isequal(remove_nan_rows(A),B_correct))
|
2 | Pass |
%%
A = 1:10;
B_correct = A;
assert(isequal(remove_nan_rows(A),B_correct))
|
3 | Pass |
%%
A = [ 1 5 8
-3 NaN 14
0 6 6];
B_correct = [1 5 8; 0 6 6];
assert(isequal(remove_nan_rows(A),B_correct))
|
4 | Pass |
%%
A = [ 1 3 6 NaN 3 NaN]';
B_correct = [1 3 6 3]';
assert(isequal(remove_nan_rows(A),B_correct))
|
5 | Pass |
%%
A = [ 1 3 6 NaN;
3 4 2 1];
B_correct = [3 4 2 1];
assert(isequal(remove_nan_rows(A),B_correct))
|
739 Solvers
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
297 Solvers
382 Solvers
Matlab Basics - Absolute Value
360 Solvers
Matlab Basics - y as a function of x
339 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!