How to create table with existing arrays?
조회 수: 225 (최근 30일)
이전 댓글 표시
N=[1,3,4,7,9,12,13,16,19,21];
i=(1:10);
Q= sqrt(N(i)*3);
CI=1./(6*(Q.^-4));
CIinDB=10*log10(CI);
t=[N',Q',CI',CIinDB']
This is the code that I have written.I want the existing arrays to be made into a table where I can add column name.And the values should be converted in integers.
댓글 수: 0
답변 (2개)
Adam Danz
2018년 7월 30일
편집: Adam Danz
2018년 7월 30일
Here's how to put your variables into a table with column names.
table(N',Q',CI',CIinDB', 'VariableNames', {'N' 'Q' 'CI' 'CIinDB'})
"Convert them to integers" - use round() for each variable above or use your 't' variable as shown below.
array2table(round(t), 'VariableNames', {'N' 'Q' 'CI' 'CIinDB'})
댓글 수: 0
Guillaume
2018년 7월 30일
I don't understand the difficulty you're facing. What's wrong with just using table to create the table directly from your variables, or array2table if you really want to go through the matrix?
N = N'; Q = Q'; Cl = Cl'; ClinDB = ClinDB'; %of course if you created N as a column vector you would not need to transpose anything
yourtable = table(N, Q, Cl, ClinDB);
or
yourtable = array2table(t, 'VariableNames', {'N', 'Q', 'Cl', 'ClinDB'});
It's all very well documented.
Note that, in
%N = a_vector_with_10_elements;
i = (1:10) %parentheses completely redundant. It's the same as i = 1:10
Q = sqrt(N(i)*3)
the little trip through i is a complete waste of time.
Q = sqrt(N)*3)
does exactly the same.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!