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

16 vues (au cours des 30 derniers jours)
Ram
Ram le 30 Avr 2018
Commenté : Ameer Hamza le 1 Mai 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.
  5 commentaires
Ram
Ram le 1 Mai 2018
Modifié(e) : Ram le 1 Mai 2018
@jan, thanks for your reply. i updated as question. after derivative the 1st row value should be same dimension as before. for ex:-190*2 after derivative also should be 190*2(values change). so i want to do derivative of each row in the 3000*1cell
Ameer Hamza
Ameer Hamza le 1 Mai 2018
@Ram, refer to my answer below. It will help you to separate and organize you required variables.

Connectez-vous pour commenter.

Réponses (2)

sloppydisk
sloppydisk le 30 Avr 2018
Should work just fine:
u = cell(5, 1);
u(:) = {rand(20, 2)};
du1 = diff(u{1})
gives me a 19x2 double.
  2 commentaires
Ram
Ram le 1 Mai 2018
Modifié(e) : Ram le 1 Mai 2018
in my case, i know the arrays(shown in above---long data size). i know if it is single array as you written. but, the cellvalues{:} represents all arrays. when i write cellvalues{:} returns 32*2. combination of all arrays in the cell output(i think).
if i write cellvalues{1} gives 190*2 same as size of array in the cell. and i have to write each cellvalues{2,3,4......20000} in each line, here, i want to get each row array derivative and then find maximum.
sloppydisk
sloppydisk le 1 Mai 2018
Please attach the relevant code so we can help you more easily.

Connectez-vous pour commenter.


Ameer Hamza
Ameer Hamza le 1 Mai 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.
  7 commentaires
Ameer Hamza
Ameer Hamza le 1 Mai 2018
Modifié(e) : Ameer Hamza le 1 Mai 2018
You need to create a script file. You cannot just paste a function definition in the command window. Also, don't try to use Evaluate selection option available in the script window. You need to run the whole script (Use Run button, or type name of the script in the command window).
If you want to run the code directly from command window then you will need to create a separate function file, with the function I wrote in my answer. After you correct this issue, other error will probably go away.
Ameer Hamza
Ameer Hamza le 1 Mai 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])

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by