フィルターのクリア

Undefined operator '-' for input arguments of type 'cell'.

6 ビュー (過去 30 日間)
Amir Antonir
Amir Antonir 2018 年 2 月 1 日
コメント済み: Star Strider 2018 年 2 月 1 日
Hi all, I am try to subtract 2 matrices, stored in 2 separate cells, and store the result in a 3rd cell. See below:
ERR_C{1,1}=10^8*(sigT_C{1,1} - recapT_C{1,1});
The error : Undefined operator '-' for input arguments of type 'cell' keeps popping up.
Can someone please assist in rectifying ?

採用された回答

Star Strider
Star Strider 2018 年 2 月 1 日
The reason it is not possible to do mathematical operations on cell arrays is that cell arrays can contain anything, including string and character data, and mathematical operations do not apply to data types such as those.
If ‘sigT_C{1,1}’ and ‘recapT_C{1,1}’ have the same internal dimensions (so you can do the subtraction), this turns out to be a two-step process:
sigT_C{1,1} = {rand(5)}; % Create Data
recapT_C{1,1} = {rand(5)}; % Create Data
ERR_C{1,1} = cellfun(@minus, sigT_C{1,1}, recapT_C{1,1}, 'UniformOutput',false);
ERR_C{1,1} = cellfun(@times, {1E+8}, ERR_C{1,1}, 'UniformOutput',false);
There are likely other ways to do this. I assume you want ‘ERR_C{1,1}’ to have the same essential structure that the argument cell arrays have, and this will produce that result.
  2 件のコメント
Amir Antonir
Amir Antonir 2018 年 2 月 1 日
Thank you Star Strider. Different dimensions was the issue.
Star Strider
Star Strider 2018 年 2 月 1 日
As always, my pleasure.

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

その他の回答 (1 件)

A. Sawas
A. Sawas 2018 年 2 月 1 日
I would suggest that you make sure that the both sigT_C{1,1} and recapT_C{1,1} are matrices. You can try this code and check if you are still getting the same error:
A = sigT_C{1,1};
B = recapT_C{1,1};
ERR_C{1,1}=10^8*(A-B);

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by