Count the values inside a cell array considering another cell array

1 回表示 (過去 30 日間)
luca
luca 2019 年 10 月 16 日
コメント済み: luca 2019 年 10 月 16 日
Hi given a cell
V={{[1,1,1,1;25,45,70,90],[2,2,2,2;78,112,146,180],[3,3,3,3;93,127,161,195],[4,4;70,100],[6;85],[9,9;85,110]},{[],[2,2,2,2;73,107,141,175],[3,3,3,3;83,117,151,185],[4,4,4,4;65,85,105,125],[6;85],[9,9,9;80,105,130]}};
and
C = vertcat(V{:});
X = ~cellfun('isempty',C);
F = @(x)sum(x(2,:)<=80);
F give us the value of which in each cell of V we exceed the value 80.
knowing this, I would like to consider R
R={{[1,1,1,1;0,-5,5,0],[2,2,2,2;34,-63,-47,-71],[3,3,3,3;34,-38,-67,-76],[4,4;20,10],[6;20],[9,9;25,-45]},{[],[2,2,2,2;34,-63,-37,-66],[3,3,3,3;34,-63,-57,-86],[4,4,4,4;20,-30,-35,-27],[6;20],[9,9,9;25,-40,-50]}};
and sum the absolute values of the second raw of each cell till the column where I've exceed 80 in V is met.
NOTE THAT V AND R have the same cell dimensions. In fact the first row of each cell in V and R are the same.
The result shoul be a matrix Y (2*6) that collect the absolute value sum of the second raw of each cell. 2 beacuse we have two cell in R, and 6 because in each cell there are 6 cell again.
Could someone help me?
  2 件のコメント
Stephen23
Stephen23 2019 年 10 月 16 日
Original question:
"F give us the value of which in each cell of V we exceed the value 80."
Actually the anonymous function F does not know anything about V, nor does it have anything to do with cell arrays. Also, you calculate X but do not use it anywhere.
Without the context of my answer those three lines are not very informative. It would be much better to just paste a link to your earlier question or to my answer.
luca
luca 2019 年 10 月 16 日
編集済み: luca 2019 年 10 月 16 日
Thanks for the comment!
May you help me Stephen?
I was thinking about substitute the first row of each cell of F with the second row of V. Then again invert the row in F and then reapeat the code you suggest me in the previous question, with sumabs instead of sum.
But do you know how to implement/substitute the rows?

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2019 年 10 月 16 日
編集済み: Stephen23 2019 年 10 月 16 日
>> Rc = vertcat(R{:});
>> Vc = vertcat(V{:});
>> X = ~cellfun('isempty',Rc) & ~cellfun('isempty',Vc);
>> F = @(r,v) sum(r(2,v(2,:)<=80)); % without ABS
>> M = zeros(size(Rc));
>> M(X) = cellfun(F,Rc(X),Vc(X))
M =
0 34 0 20 0 0
0 34 0 20 0 25
Or if you really want to sum the absolute values:
>> F = @(r,v) sum(abs(r(2,v(2,:)<=80))); % with ABS
>> M = zeros(size(Rc));
>> M(X) = cellfun(F,Rc(X),Vc(X))
M =
10 34 0 20 0 0
0 34 0 20 0 25
  6 件のコメント
Stephen23
Stephen23 2019 年 10 月 16 日
>> C = vertcat(R{:});
>> X = ~cellfun('isempty',C);
>> F = @(x)sum(max(0,x(2,:)));
>> M = zeros(size(C));
>> M(X) = cellfun(F,C(X))
M =
5 34 34 30 20 25
0 34 34 20 20 25
luca
luca 2019 年 10 月 16 日
THANKS A LOT

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by