Cell arrays difference operation

3 ビュー (過去 30 日間)
EldaEbrithil
EldaEbrithil 2020 年 8 月 14 日
コメント済み: EldaEbrithil 2020 年 8 月 14 日
Hi all
i have a 2 cell arrays, Twcell_hot and tempTOT_hot;Twcell_hot is a 1x285 array where in each cell there is a single number, and tempTOT_hot is a 1x285 array where in each cell there is a column of 261 numbers. I want to perform the difference between each value in Twcell_hot and tempTOT_hot. I have tried with this code but with no success... I don't want to convert cell to matrices because i need cells in the computation
Tahank you for the help
for i=1:length(yendhot)
if abs(Twcell_hot{i}(1)-tempTOT_hot{i}(:,1))<20
temp_eq_hot{i}=tempTOT_hot{i};
end
end
  2 件のコメント
jonas
jonas 2020 年 8 月 14 日
First of all it seems unnecessary to use cell arrays. If I understand it correctly, you have one 1x285 array and one 261x285 array and they are all numbers.
Anyway, the if statement
if abs(Twcell_hot{i}(1)-tempTOT_hot{i}(:,1))<20
...will probably return an array of logicals. This "works" but is probably not what you want to do.
Do you actually want to calculate the difference between each column in tempTOT_hot and the corresponding scalar in Twcell_hot and then store any values where the difference is less than 20 (degrees?).
EldaEbrithil
EldaEbrithil 2020 年 8 月 14 日
Thank you for the reply, yes i want to do what you have written

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

採用された回答

jonas
jonas 2020 年 8 月 14 日
編集済み: jonas 2020 年 8 月 14 日
First of all I would use cell2mat() to concatenate your cell array tempTOT_hot into a 261x285 array (double)
Then everything is much easier. You can make "column-wise" subtraction of arrays with size 1xn and a mxn.
%Some random data
T1 = rand(1,285).*100; %1 row, 285 columns
T2 = rand(261,285).*100; %261 rows, 285 columns
T_diff = abs(T2-T1); %calculate difference
%remove any values from T2 with an absolute difference of less than 20;
out = T2;
out(T_diff<20) = NaN;
Not sure if it is the output you're looking for.
  3 件のコメント
jonas
jonas 2020 年 8 月 14 日
No problem!
I believe you can make the conversion from cell to mat simply by:
double_matrix = [cell_array{:}]
EldaEbrithil
EldaEbrithil 2020 年 8 月 14 日
or maybe using cell2mat

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by