Save matrix from "writematrix" to clipboard

조회 수: 3 (최근 30일)
Tim Schaller
Tim Schaller 2023년 2월 18일
댓글: Tim Schaller 2023년 2월 19일
Hi, I need to save a matrix to the clipboard. Because the points need to be seperated by comma, I used the function "writematrix".
a = [1 2 4;5 6 7;8 9 10];
writematrix(a,'Bachelorarbeit.txt')
type Bachelorarbeit.txt
1,2,4 5,6,7 8,9,10
Now i need to save the matrix shown in Matlab to the clipboard. Is there a way to do so? I could not find anything.
Thanks for helping me.
  댓글 수: 2
Md. Al-Imran Abir
Md. Al-Imran Abir 2023년 2월 18일
There is a function named clipboard (clipboard) which might help you.
Tim Schaller
Tim Schaller 2023년 2월 18일
Hi, I already tried it with clipboard. The problem is that I need to save it in the exact way it is shwon in the text file. But I don't know how to do that.

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2023년 2월 18일
You've got to create the entire text as a string or char() variable.
It would be more efficient to avoid the intermediary disk file...
a = [1 2 4;5 6 7;8 9 10];
fmt=[repmat('%g,',1,size(a,2)-1) '%g\n'];
clipboard('copy',sprintf(fmt,a.'))
content=clipboard("paste")
content =
'1,2,4 5,6,7 8,9,10 '
  댓글 수: 3
Tim Schaller
Tim Schaller 2023년 2월 19일
in my code the matrix looks like this, but is much longer
a =
0 0 1.000000000000000
0.017150418627992 0 0.823370357174576
0.072731407686129 0 0.654969826345343
0.167425334872282 0 0.505049838368501
0.293716496272837 0 0.380416474388619
0.441054925718054 0 0.281320429539904
Tim Schaller
Tim Schaller 2023년 2월 19일
I fugured it out by myself. You just need to change the mode of sprintf form g to f.
Thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by