0
votes

What I ultimately need is to input a 2-column matrix, run it through a bunch of conditions and have an output of the 2 original columns plus an additional three.

My initial data matrix I split into several arrays according to time (the second column) and continue with applying my conditions on each array individually:

A = arrayfun(@(x) M(M(:, 2) == x, :), unique(M(:,2)), 'uniformoutput', false);
n = numel(A);
k = 0;

for i = 1:n                             % for each # of arrays 
    matrix = A{i};                      % array i
    dat = size(matrix);
    length = dat(1,1);                  % length of i array  
    adductName = zeros(length, 1);      % preallocate columns  
    actualMass = zeros(length, 1);
    adductMass = zeros(length, 1);
    %... continued with conditions here's an example of one

    for r = 1:length                    % for the length of array i
        mass = matrix(1,r);
        M = mass-1;

        k=k+1;
      if any(M ==  matrix(:, 1))        % if any M matches rest of column 1 in array
         adductName(k) = 'M';
         actualMass(k) = M;
         adductMass(k) = mass;
      else
         adductName(k) = 'None';
         actualMass(k) = 0;
         adductMass(k) = 0;

adductName, actualMass and adductMass are the three additional columns I need added in my output

My question is, how do I recombine all of my arrays, A{i}'s along with my additional three columns into one data matrix to be outputted?

1
Please post runnable code - Luis Mendo

1 Answers

0
votes

You can either use the [ ] operator or explicit calls to horzcat or vertcat to concatenate matrices in different ways. See the Creating and Concatenating Matrices documentation part for further reference.