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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!