printing a table made of 3 arrays
17 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm sorry if this is a very simple quiestion but I am having trouble finding the reference I need.
I have 3 arrays of 100 points (x values and the respective values of two functions).
I am attempting to print them into a table of three columns (x, p1, p2)
I tried disp(table(x, p1, p2) and it only displayed [1x100 array] instead of any data.
Any advice someone could give me?
I just need to save the data of these arrays into a table than I can save elsewhere. Is there a way to just copy the data and put it in excel or something?
thanks!
0 个评论
采纳的回答
Simon Chan
2021-7-25
You can write the entire table to excel using the following code:
However, please make sure that they are all column vectors and having same number of rows.
writetable(table(x,p1,p2),'result.xlsx','UseExcel',true,'WriteMode','append');
0 个评论
更多回答(1 个)
dpb
2021-7-25
disp() just displays something to the command window without the "variable =" prefix; it doesn't save anything. Also, the hint that it showed a 1x100 array shows that your variables are row, not column vectors. table will put a row vector on a row in a table as an array; you need to store them to a table as column vectors instead...
tData=table(x(:),p1(:),p2(:),'VariableNames',{'X','P1','P2'});
The (:) will ensure the variables are column vectors but table won't pick up the variable names with it in the argument list as MATLAB creates a temporary; hence the variable names given (besides that I think the capitals look nicer with numeric suffixes than do lowercase). Obviously, "salt to suit!"
Use writetable to save to a file
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!