Matlab programmingSolutionFollowing is the matlab code Pleas

Matlab programming

Solution

Following is the matlab code. Please note that, extractSeq( 3, 4, mat, 2 ) should return [15,19] unlike mentioned in problem statement.

function [out] = extractSeq( r, c, mat, n )
    [ totalRows, totalCols ] = size( mat );
    out = [];
    if r > totalRows
        fprintf(\'Error: the given r exceeds the number of rows.\ \');
    elseif c > totalCols
        fprintf(\'Error: the given c exceeds the number of columns.\ \');
    elseif ( c + n - 1 > totalCols )
        fprintf(\'Error: Not enough numbers to make a sequence.\ \');
    else
        out = 0:n-1;
        for i=0:n-1
            out(i+1) = mat(r,c+ i);
        end
    end

end

Matlab programmingSolutionFollowing is the matlab code. Please note that, extractSeq( 3, 4, mat, 2 ) should return [15,19] unlike mentioned in problem statement

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site