Keyboard shortcut for semicolon

31 views (last 30 days)
Ismaeel
Ismaeel on 22 Mar 2015
Commented: Walter Roberson on 23 Apr 2023
Hi...
Is there any keyboard-shortcut to write semicolon (;) at the last of selected lines?
Like (CTR+R) for putting (%) at the beginning of lines.
I have data with large entry and it requires me long time to do that for every case.
Thanks
  11 Comments
Image Analyst
Image Analyst on 23 Apr 2023
There is no single keystroke shortcut. You can do two keystrokes with "end" and then ";".
Walter Roberson
Walter Roberson on 23 Apr 2023
If the point is to supress output, then there may be another possibility. In the regular editor at least, if you do not supress output on an assignment, the editor will underline the = with orange. If you move the cursor position to either immediately before or at the = then you then have three choices:
  • if you hover for a second an explanation will appear and the right side of that will have a Fix button you can click
  • if you right-click before or at the = then a menu will appear, the first option of which is to add the semi-colon
  • or when you are positioned before or at the =, press alt-return (return == option return on Mac). This will insert semi-colon at the end of the expression -- which is where you would want it put rather than end of line, since end of line might be a comment.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 23 Mar 2015
Edited: Stephen23 on 22 May 2015
Your concept of how to use MATLAB is making your own life more difficult.
Instead of copying the data into Mfiles and trying to execute this, you should simply keep your data where it is and read the data itself into MATLAB using one of its many functions designed exactly for that purpose: csvread, dlmread, textscan, or any or of the other data reading functions that you will find in the MATLAB documentation on file reading and writing .
The reason there is no shortcut is because trying to build large executable data files is poor programming practice, and no programmer writes large executable files of their data: this is generally considered to be a buggy and inefficient process, and as has already been commented on in this page by per isakson and John D'Errico.
In MATLAB, like most programming languages, data and the executable code are considered to be two different paradigms and are not usually stored together or handled in the same way. This helps make code more robust, by allowing us to create code that is generalized to a reasonable degree and not specific to one set of data. It also allow us to change the data without having to change the code itself. Keeping them separate encourages writing re-usable and generalized code, rather than writing code for one specific set of data.
It would be more usual to store simple numeric data in something like a .CSV file, some kind of binary file or a .MAT file, and import this into MATLAB using the usual file-reading functions.
For example you might have some numeric and image data from an experiment: these would normally be kept in the simplest storage form possible, and only read into MATLAB when required. You can see that making the numeric data a callable script or function is rather unbalanced, as the image data would likely not get treated like this.
This topic has been discussed before on MATLAB Answers:
  1 Comment
Ismaeel
Ismaeel on 23 Mar 2015
Edited: Ismaeel on 23 Mar 2015
Thanks Stephen, I got it. Appreciate your suggestion.

Sign in to comment.

More Answers (0)

Categories

Find more on Desktop in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!