필터 지우기
필터 지우기

How to combine array columns to form complex number?

조회 수: 23 (최근 30일)
Ted Baker
Ted Baker 2019년 12월 18일
댓글: Stephen23 2019년 12월 18일
I'm trying to combine two columns from two arrays to form a complex number. I know I can create a complex number using the complex(a,b) function and I think I am correct in addressing each column in the two arrays as S21real(:,2) and S21imag(:,2). As a results my code looks like
S21complex = complex(S21real(:,2), S21imag(:,2));
Where my data looks like
S21real:
690000000 0.00854245859320000 0
690193750 0.00915901995335000 0
690387500 0.00963277694145000 0
S21imag:
690000000 0.00854245859320000 0
690193750 0.00915901995335000 0
690387500 0.00963277694145000 0
However, when I run the code, I get the following error:
Error using complex
Real input A must be numeric, real, and full.
Can anyone shed some light as to where I am going wrong?
  댓글 수: 3
Ted Baker
Ted Baker 2019년 12월 18일
I'm in 2019b too. :/ Here is my full code. I've attached the two full data files.
I am 99% sure I am working in the correct directory, etc.
% Parameters
filenamei = 'S21_I_BOOT_DRIVER_DIRECT.CSV';
filenamer = 'S21_R_BOOT_DRIVER_DIRECT.CSV';
S21imag = readtable(filenamei, 'HeaderLines', 3);
S21real = readtable(filenamer, 'HeaderLines', 3);
S21complex = complex(S21real(:,2), S21imag(:,2));
Stephen23
Stephen23 2019년 12월 18일
You use parentheses to access the two S21xxx tables, which the MATLAB documentation
makes clear, returns a table. But complex is not defined for table inputs.
To get the contents of that table (e.g. a numeric array) you need to use the correct indexing: curly braces {} or dot notation with the specific variable names.

댓글을 달려면 로그인하십시오.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2019년 12월 18일
Since you used table, you need to run
S21complex = complex(S21real.Var2, S21imag.Var2)
  댓글 수: 1
Ted Baker
Ted Baker 2019년 12월 18일
Thank you for the answer. It worked perfectly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by