hi,
I have 2 .mat file that their type is: comp int8
i want sum this 2 togheter (one by one array)
i used this:
A=load('CDdata1.mat');
B=load('CDdata2.mat');
C=A+B
but it said:
Undefined operator '+' for input arguments of type 'struct'.
Error in Untitled (line 5)
C=A+B

2 commentaires

madhan ravi
madhan ravi le 1 Déc 2018
upload .mat files
art trip
art trip le 2 Déc 2018

Connectez-vous pour commenter.

Réponses (1)

dpb
dpb le 1 Déc 2018
Modifié(e) : dpb le 2 Déc 2018
The assignment of LOAD to a LHS variable creates a struct of the variable name provided with the fields the variable names in the .mat file. Hence, your variables are
A.CData1
B.CData2
where CData1/2 are the actual variables in the .mat files...you don't give us those.
C=A.CData1 + B.CData2;
is the syntax if variables are known and fixed. If there could be different variables inside the .mat files, use the dynamic field names options and/or structfun to write generic code--I just did another similar Answer here: https://www.mathworks.com/matlabcentral/answers/433003-average-and-plot-variable-from-multiple-mat-files#answer_349836 for how that can work.
ADDENDUM:
I just discovered for some unfathomable reason, "Complex integer arithmetic is not supported" -- How rude... :(
Besides the issue of duplicate variable names, you'll have to either cast to double to do the sum or as another poster noted, add the real and imaginary parts separately.
C=int8(double(A.data)+double(B.data));
if want/need the resultant to also be int8
Of course, you have to be aware of possible overflow altho it doesn't appear to be an issue with the specific dataset.

Catégories

Question posée :

le 1 Déc 2018

Modifié(e) :

dpb
le 2 Déc 2018

Community Treasure Hunt

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

Start Hunting!

Translated by