Copy-pasting variables (values) to edior in 2021b

조회 수: 13 (최근 30일)
Mikolaj Czajkowski
Mikolaj Czajkowski 2021년 10월 22일
답변: fer ef 2024년 8월 16일
Copy-pasting column vector values from workspace to editor used to automatically include ; and give me everything in a nicely formated single row. After updating to 2021b it results in a long list of values (each one in a separate row).
For example:
Create a column vector:
> A = [1; 2; 3; 4; 5];
Open it in the workspace, select entire column and copy (ctrl-c)
Paste in the editor results with:
1
2
3
4
5
while it used to result with:
1;2;3;4;5
Is there a way to switch back to the old behavior of copy-pasting variables?
I use it a lot, for example when saving the results in my scripts as starting values for the future and the new format makes the scripts much longer and messier.
Thank you very much in advance for any suggestions.
  댓글 수: 1
Seok Yoon Jeong
Seok Yoon Jeong 2021년 11월 24일
I meet same issue in R2021b.
The previous version did wonderful job. why they eliminiate it?
Have you fix this problem?

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

답변 (4개)

DGM
DGM 2021년 10월 23일
편집: DGM 2021년 10월 23일
Just don't rely on some sort of automagic formatting of pasted content. If you want to save an array variable as a literal constant, just convert it according to your needs using mat2str() or something.
A = rand(5,1) % a test array
A = 5×1
0.8996 0.1371 0.2541 0.4809 0.3265
mat2str(A,5) % or however many digits you want
ans = '[0.89963;0.13708;0.25414;0.48086;0.32655]'
A = randi(9,5,1) % same thing, but integers
A = 5×1
2 5 9 5 9
mat2str(A) % again
ans = '[2;5;9;5;9]'
mat2str() will give you an expression which can simply be copied and pasted.
Otherwise, you can always just save the variables to a mat file or something and load them as needed.
  댓글 수: 4
DGM
DGM 2022년 1월 7일
Workarounds are generally terrible by definition when compared to a scenario which obviates the necessity for workarounds.
If you know of a better workaround to which the one I offered is by far worse, feel free to post it. That's not sarcarsm. I have no stake in this.
For what it's worth, I don't use R2021x, and I doubt I ever will. The creeping integration of these new UI components is gradually breaking everything for me. I don't need MATLAB to be slower and flakier than it already is.
Ornit
Ornit 2022년 12월 13일
I experiance the same problem with R2022a. Thanks Mikolaj Czajkowski for posting the question.
Thanks, DGM for the solution. mat2str() worked for me AND I learned another function that I have never encountered before.

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


Walter Roberson
Walter Roberson 2022년 1월 7일
Put a [ in your code and then paste and then put a ]
The line breaks inside [] are treated as semi-colon
  댓글 수: 2
Mikolaj Czajkowski
Mikolaj Czajkowski 2022년 7월 22일
편집: Mikolaj Czajkowski 2022년 7월 22일
Hi Walter - thanks.
I know it works like this. But the thing I often used this for was copy-pasting arrays with starting values to my data analysis/optimization scripts. If I keep it like this in my scripts it generates tons of lines making the script diffuicult to follow.
In the mean time, I found that it must be the 'paste' to editor behavior that has changed, because 'copy' in the new and old version works the same (extracts the same data in the same format).
Is there a specific function in Matlab that deals with pasting values from clipboard to editor (particularly, using ctrl-v)? I could then modify it and that would solve it.
Walter Roberson
Walter Roberson 2022년 7월 22일
I do not know. I would tend to think that level would be built in functions, not matlab code.

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


Mikolaj Czajkowski
Mikolaj Czajkowski 2024년 5월 13일
A quicker method (than mat2str) in MATLAB 2024a for maintaining compact formatting involves copying a variable from the workspace, pasting it into the Command Window, and then copying it from there to paste into your script or editor.

fer ef
fer ef 2024년 8월 16일
I encounter the same problem in 2021b. While others above say that mat2str() works, I found the following is more easy to use. That is, paste the text first in the command line.
For unknown reason, pasting in the command line will produce the results: [1;2;3;4;5] as previous Matlab versions. However, pasting in the edition produces
1
2
3
4
5
Therefore, it would be convenient to paste in the command line firstly and then recopy the texts from the command line.
It works fine for me

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by