Effacer les filtres
Effacer les filtres

Can I update my Matlab behavior

1 vue (au cours des 30 derniers jours)
Madmad
Madmad le 15 Mai 2024
Commenté : Madmad le 15 Mai 2024
Sorry for the poor title, not sure how to explain it.
I have two questions:
1) When we write three dots to split a command line, can we change what happens?
examplepath = 'this\is\a\path\'; % This is a random string
examplepath = ['this\is\a\...' ...
'path\']; % this is the same string if I write three dots "..." somewhere
% This is a bad behavior because it breaks the string
%% What I want Matlab to do when I write three dots:
examplepath = ['this\is\a\', ...
'path\'];
This is what I want to do when I write three dots and press enter, I want to split whatever I wrote so it fits on 2 lines and I don't have to use the horizontal slider bar because my sentence is too long. Is it be possible to update such behavior?
2) Indentation changed a few versions ago, I now use 2023a.
If I have a loop for example, when I paste code to it, I want it to be indented where it should be by default, not at the begining of the line. Example:
for i = 1:10
% something I wrote here here
% someting I pasted
end
%% It should be:
for i = 1:10
% something I wrote here here
% someting I pasted
end
It would be great to save these selection + ctrl+i, clicking at a random place inside a loop before was giving you an indented space, I want the same behavior.
Thanks!

Réponses (2)

Walter Roberson
Walter Roberson le 15 Mai 2024
In the MATLAB editor, if you start with
examplepath = 'this\is\a\path\'
and position your cursor at the path part and press return, then MATLAB will automatically split it into
examplepath = ['this\is\a\' ...
'path\']
  1 commentaire
Madmad
Madmad le 15 Mai 2024
Oh I see, I was writing the three dots myself and then pressing enter, that's why it duplicate dots and does not add a comma!

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 15 Mai 2024
Sometimes when pasting text in the indentation in the course was a mixture of tabs and spaces so the alignment is off.
To fix the indenting, have the cursor in the editor window and type control-a and then control-i.
I don't understand what you mean when you're manually breaking up a long string by typing an apostrophe, three dots, and then enter etc. I don't know of any function (keystroke shortcut) to take your long string and break it into multiple lines automatically.
  1 commentaire
Madmad
Madmad le 15 Mai 2024
For the line split, it is okay as I just had to press enter to automatically split it, I was typing the three dots and pressing enter myself.
For your indenting proposition, I cannot use ctrl+a, as it select my entire script, which is usually several loops/trycatchend as I like to have code I can read fast. The issue is when pressing ctrl+i, it makes me reach the end of the script, so I lose my current position, threfore I cannot use ctrl+a and I have to manually select the section and then ctrl+i (a bit of a waste of time when you do it 50 times a day)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by