Export/Copy Plot Line Values

4 ビュー (過去 30 日間)
Sami Case
Sami Case 2021 年 5 月 16 日
コメント済み: Star Strider 2021 年 5 月 16 日
I need to be able to copy the values of a line from my plot. I know that the line is saved as a 1x70 vector in the workspace, but is there a function to copy these numbers to the clipboard. I ultimately want to use this function in the app designer, so saving directly from the workspace isn't ideal.

採用された回答

Star Strider
Star Strider 2021 年 5 月 16 日
Try siomething like this —
x = 0:10;
y1 = x.^2;
y2 = 50*sin(2*pi*x/10)+50;
figure
hp = plot(x, y1, x, y2);
Line1X = hp(1).XData
Line1X = 1×11
0 1 2 3 4 5 6 7 8 9 10
Line1Y = hp(1).YData
Line1Y = 1×11
0 1 4 9 16 25 36 49 64 81 100
Line2X = hp(2).XData
Line2X = 1×11
0 1 2 3 4 5 6 7 8 9 10
Line2Y = hp(2).YData
Line2Y = 1×11
50.0000 79.3893 97.5528 97.5528 79.3893 50.0000 20.6107 2.4472 2.4472 20.6107 50.0000
.
  2 件のコメント
Sami Case
Sami Case 2021 年 5 月 16 日
What function can I use to copy each of these values to a system clipboard to export them as a excel type array?
Star Strider
Star Strider 2021 年 5 月 16 日
I doubt that there is a specific function for that. You would likely have to do something like this —
x = 0:10;
y1 = x.^2;
y2 = 50*sin(2*pi*x/10)+50;
figure
hp = plot(x, y1, x, y2);
Line1X = hp(1).XData.';
Line1Y = hp(1).YData.';
Line2X = hp(2).XData.';
Line2Y = hp(2).YData.';
T1 = table(Line1X, Line1Y, Line2X, Line2Y)
T1 = 11×4 table
Line1X Line1Y Line2X Line2Y ______ ______ ______ ______ 0 0 0 50 1 1 1 79.389 2 4 2 97.553 3 9 3 97.553 4 16 4 79.389 5 25 5 50 6 36 6 20.611 7 49 7 2.4472 8 64 8 2.4472 9 81 9 20.611 10 100 10 50
writetable(T1,'YourFileName.xlsx')
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by