MATLAB: Sending/calling every row of matrix to another function from current function

digital signal processing

Hi guys !
I have built a function that gives me a matrix that its size is mXn , this function is:
function TruncatedSubstring=Truncated(input1,substring) % this function gives me a matrix of all substrings occurances at each row
N = 16;
positions = strfind(input1(1:end-N+1), substring);
TruncatedSubstring= cell2mat(arrayfun(@(idx) input1(idx+length(substring):idx+length(substring)+N-1), positions, 'uniform', 0 ).');
end
I want to take every row that's found in the output of my above function, in other words every row of the matrix TruncatedSubstring and send it to another function (found in another script), the other function called function DoSomething=Dosomething(substring) and it's found in another script..so I want to call that function in the function TruncatedSubstring with given input every row of the matrix TruncatedSubstring.
function DoSomething=Dosomething(substring)
%function that does and manipulate some operations on given substring-in other words in my case in my current matrix's row at every call to that function
the function DoSomething does some operations/manipulations on the given input called substring.
substring is an input to function Dosomething that's implicitly equal to every row of matrix output of the called function(I call the function Dosomething with every row output matrix as input to that function)
To clarify more, I will example a more concerete example:
lets assume the output of function TruncatedSubstring is a matrix size 2X50, this means that the rows I 2 and at every row I have implicitly substring .. so I want to call at every row of the output TruncatedSubstring the function Dosomething(current matrix row vector) with current row of the matrix output of function TruncatedSubstring, so in my case here I call twice the function Dosomething, and first call (call to function Dosomething)with input the first matrix row vector, the second call with input the second matrix row vector…..till I finish the row output vectors(rows of output matrix of TruncatedSubstring function)
How can I implement that in matlab? thanks alot !

Best Answer

  • [N,~] = size(TruncatedSubstring); % N = number of rows
    for i=1:N
    substring = TruncatedSubstring(i,:)
    Result(i,:) = Dosomething(substring)
    end