Hi All, I have table, named as newT consisting of data value and position(latitude and longitude). What I want to do is:
  1. How to delete empty cell in the table?
2. How to some operationss with them? each cell in each grid contains, I want to do sum operation (for example in the figure above: 16+57+202......) and average in each rows. Then, the calculation is the same for all grids.
Any helps is greaty appreciated.
Thank you

 Réponse acceptée

Walter Roberson
Walter Roberson le 12 Avr 2021

0 votes

Removing entries that have empty exData:
mask = cellfun(@isempty, newT.exData);
newT(mask,:) = [];
If I understand correctly, each row of exData contains a cell array that contains cells with variable number of numeric entries. If so then
result1 = cellfun(@(C) cellfun(@sum, C), newT.exData, 'uniform', 0)
The result would be a cell array with one entry for each row in newT, and the entries would be vectors that were the sums. If you then wanted to take the average of those sums, then
result2 = cellfun(@mean, result1)
which would give you a numeric vector, one entry per row in newT.

3 commentaires

Ahmad Bayhaqi
Ahmad Bayhaqi le 12 Avr 2021
Thank you very much for you help.
Great,,,
It works for me.
for the code of result1 is right, but what I want is :
  1. How the get to know the size for each row? for the example (figure 2), the size of row is 16. Because the sum values from code 'result1" will be divided of the size of each row. Then, it will get the average value in each row.
  2. After that, the sum for all averages in each row will be divided by the size of each cell of each grids (figure 1).
Is that possible?
Thank you very much.
Have you considered
result3 = cellfun(@(C) cellfun(@mean, C), newT.exData, 'uniform', 0)
instead of having to count and divide yourself ?
... I am not clear as to what is being averaged, to be honest.
Ahmad Bayhaqi
Ahmad Bayhaqi le 13 Avr 2021
Thank you so much for your great help.
I get inspiration from your answer.
Big thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by