how to find a differentiation or derivative of each array(>1000*2) in cell consists 7000*1?
17 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Ameer Hamza
il 1 Mag 2018
@Ram, refer to my answer below. It will help you to separate and organize you required variables.
Risposte (2)
sloppydisk
il 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 Commenti
Ameer Hamza
il 1 Mag 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 Commenti
Ameer Hamza
il 1 Mag 2018
Modificato: Ameer Hamza
il 1 Mag 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
il 1 Mag 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])
Vedere anche
Categorie
Scopri di più su Get Started with MATLAB in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!