How to sum 2 .mat file (Complex int)
이전 댓글 표시
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
답변 (1개)
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.
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!