# how to find a differentiation or derivative of each array(>1000*2) in cell consists 7000*1?

30 views (last 30 days)
Ram on 30 Apr 2018
Commented: Ameer Hamza on 1 May 2018
Hi, let say, there are 700*1 cells. each cell consists of arrays(3000*2). i would like find the derivative of each cell and find its max and min values. combine derivative values min and max separately. my data(cell) looks like,
this 3000 rows*1 column cell data
{
[190*2] %1st row
[180*2] %2nd row
[186*2]
[195*2]
[182*2]
[183*2]
[122*2]
[183*2]
[100*2]
.......... %3000 row}
my code:-
%here cellvalues{i} are in 3000*1
first_derivative = diff(cellvalues{i}) provides 32*2 double values.
but each array in cell has 190*2/180*2/600*2....? when i run above why i am getting only 32*2 values but the entire cell data has 2000*1?
%try to do derivatives of each cell %other way
du = diff(cellvalues{:}) or
first_derivative = diff(cellvalues{i:end}) gives error or many arguments.
Ameer Hamza on 1 May 2018
@Ram, refer to my answer below. It will help you to separate and organize you required variables.

sloppydisk on 30 Apr 2018
Should work just fine:
u = cell(5, 1);
u(:) = {rand(20, 2)};
du1 = diff(u{1})
gives me a 19x2 double.
##### 2 CommentsShowHide 1 older comment
sloppydisk on 1 May 2018

Ameer Hamza on 1 May 2018
You can process, and organize the data with the following code. It will create a struct array which you can use to easily access all the data.
y = cellfun(@processData, x);
here processData is the following function
function out = processData(x)
out.derivative = diff(x);
out.min = min(out.derivative);
out.max = max(out.derivative);
end
create a .m file with this function and save it in Matlab path and then run the above line.
Ameer Hamza on 1 May 2018
Let me summarize the procedure,
• Create a new function file or add this function to the end of you existing file
function out = processData(x)
out.derivative = diff(x);
out.derivative = out.derivative(:, 2)./out.derivative(:, 1);
out.min = min(out.derivative);
out.max = max(out.derivative);
end
• If you created a new function file then run the following from command window. If you added it to script file, add the following line to your script above function definition
y = cellfun(@processData, x);
Here x in your cell array and y is the output struct array.
• plot the max values using
plot([y.max])