How to manipulate arrays inside a cell array?
Afficher commentaires plus anciens
Hi,
I have a cell array(1x316) which contains 316 double numeric arrays of various sizes like
{74845x2 double}, {81032x2 double}, {87351x2 double},.....
sample of one array inside the cell-array :
{74845x2}=
0.194 0.0043
0.116 0.0040
0.118 0.0041
0 0.0044
0 0.0037
0 0.0042
0.045 0.0041
0.151 0.0043
0
0.231 0.0040
0
.....................
.....................
Now, Steps to be taken: 1)
Check if the first column values are non-zero,if it is true then, find difference of elements in first and second column separately.
EDIT
There are two cases here:
case i)If there are more than one non-zero elements together in first column then,
find the maximum and minimum values in the group and compute difference as (max-min).
d11 = 0.194(max among 0.118, 0.116, 0.194)- 0.116(Min value of those)
d12 = 0.0043(max among 0.0041, 0.0040, 0.0043)- 0.0040(min of those)
d21 = 0.151-0.045 d22 = 0.0043-0.0041
case ii)If there is only one non-zero element in the first column, no need to take difference.The output should be same.
d31 = 0.231 d32 = 0.0040
2)At last, remove all the zero values from all arrays in the cell.
This way, i need to compute differences among non-zero elements from all the 316 arrays in the cell array and save the results in a new cell array of original size 1x316.
Please help me out on this.
Thanks in advance!
Réponse acceptée
Plus de réponses (1)
Jos (10584)
le 14 Avr 2016
Write a function that does this for a single element of the cell array and then use cell fun If you can write the function as an inline function that will be nice, otherwise write an m-file to do this. As an example
fh = @(x) abs(x(:,1) - x((:,2)) % difference between largest and smallest
OUT = cellfun(fh, YourCellArray)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!