Finding the locations of non-similar value cells

2 ビュー (過去 30 日間)
Austin Sowers
Austin Sowers 2019 年 5 月 1 日
編集済み: Austin Sowers 2019 年 5 月 1 日
I have varying in size numeric cells within a cell array that contain random numbers betweem -10 and 200. I have another cell array with the same dimmensions as the first, only with different random values.
Lets call the 2 cell arrays “CA” and “CB”
I want to determine the cell array locations where there is a -10 in an "X" location in cell array CA, but not in cell array CB so that I may manipulate those specific values.

回答 (1 件)

the cyclist
the cyclist 2019 年 5 月 1 日
編集済み: the cyclist 2019 年 5 月 1 日
I'm not certain I understand exactly what you want, but this is my best guess:
% Define input arrays
CA = {[-10 2],[6;6]};
CB = {[17 2],[6;6]};
% Logical index to locations where CA includes a value of -10, but CB does not
idx = cellfun(@(x)any(x(:)==-10),CA) & not(cellfun(@(x)any(x(:)==-10),CB));
  3 件のコメント
the cyclist
the cyclist 2019 年 5 月 1 日
What specifically do you want the output to be, for my example?
Austin Sowers
Austin Sowers 2019 年 5 月 1 日
編集済み: Austin Sowers 2019 年 5 月 1 日
CA = {[5 -10 2],[6 6 8],[0 9 -10 8 -10 3]};
CB = {[4 17 2],[6 6 10],[9 3 4 9 7 6]};
CC = {[1 2 4],[4 2 1],[1 7 3 1 2 2]};
for i = 1:length(CA)
idx = CA{i}==-10 ;
CB{i}(idx) = CB{i}(idx)+15 ;
end
I have figured out the first part. My output I wanted is the "new" CB generated in the for loop.
but now instead of adding 15 to all of them, I want to add different numbers to each depending on "CC." For example:
Just looking at the first group of each cell:
CA = {[5 -10 2]}
CB = {[4 17 2]}
CC = {[1 2 4]}
I would like to add the difference between the "1 and 4" in CC (l1-4l=3), to the "17" in CB.
So the first group in the "new" CB will be {[4 20 2]}.
BTW. I chose the numbers "1 and 4" in CC because they are the numbers that would be adjacent to the -10 in CA.

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by