Reputation: 23
I'm a beginner at Matlab and I need to solve a problem that seems to be easy.
I have two cell arrays of the same size; 'hh:mm' (Col1) and data (Col2). I need to make the division of each value in column 2 of cell array A by cell array B and create a new cell array with the results as follows:
Cell A= {'00:40', [5.5];'00:45', [10.0]}
Cell B= {'00:40',[2.25];'00:45', [5.0]};
The result is:
Cell C= {'00:40', [2.44]; '00:45', [2.0]}
I've already tried the cat and cellfun commands, but without sucess! I've data from 00:00 to 24:00 hours.
Any help will be appreciate.
Upvotes: 2
Views: 1973
Reputation: 36710
%Copy first col
C=A(:,1)
%calculate second col
C(:,2)=cellfun(@rdivide,A(:,2),B(:,2),'UniformOutput',false)
The 'UniformOutput',false
causes cellfun
to return a cell
, otherwise a vector is returned.
Upvotes: 2