MATLAB Answers

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

27 views (last 30 days)
Mikolaj Czajkowski
Mikolaj Czajkowski on 22 Oct 2021
Commented: Mikolaj Czajkowski on 24 Nov 2021 at 11:00
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 Comment
Seok Yoon Jeong
Seok Yoon Jeong on 24 Nov 2021 at 9:32
I meet same issue in R2021b.
The previous version did wonderful job. why they eliminiate it?
Have you fix this problem?

Sign in to comment.

Answers (1)

DGM
DGM on 23 Oct 2021
Edited: DGM on 23 Oct 2021
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.
  1 Comment
Mikolaj Czajkowski
Mikolaj Czajkowski on 24 Nov 2021 at 11:00
Thanks. Yes, this work-around works, but it is more effort than using the previous copy-pasting behavior.

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!