printing a table made of 3 arrays

16 ビュー (過去 30 日間)
Ethan Anderson
Ethan Anderson 2021 年 7 月 25 日
回答済み: dpb 2021 年 7 月 25 日
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!

採用された回答

Simon Chan
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');

その他の回答 (1 件)

dpb
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

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by