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

Jan
Jan 2015년 3월 22일
Please explain, what "data with large entry" is. What exactly is "every case"?
per isakson
per isakson 2015년 3월 22일
"data with large entry" &nbsp Large amounts of data should be stored in special data files and not cause problems in the m-files.
John D'Errico
John D'Errico 2015년 3월 22일
AS Per points out, I think the problem is you are trying to enter data by storing it in m-files, to be executed.
You are trying to fix a problem that is caused by use of the wrong tool. Just use data files, that you will then load.
Ismaeel
Ismaeel 2015년 3월 23일
Thanks Jan, I got your point. Appreciate it.
Rena Berman
Rena Berman 2022년 1월 10일

(Answers Dev) Restored edit

Aryan Ritwajeet Jha
Aryan Ritwajeet Jha 2023년 4월 23일
So, what is the shortcut, if there is any? (I'm not working with large datasets or anything, just don't supress the output initially and then want to supress the output after viewing it once).
@Aryan Ritwajeet Jha if you want an output echoed the first time, but not in subsequent times, just do something like this
for k = 1 : whatever
if k == 1
output = GetMyOutput % No semicolon the first time through so it will echo to command window.
else
output = GetMyOutput; % Use a semicolon for subsequent iterations so output will not show up in the command window.
end
end
Compare:
A = [6 6 2;
2 6 9;
2 1 6;
5 5 8;
5 6 1]
A = 5×3
6 6 2 2 6 9 2 1 6 5 5 8 5 6 1
B = [6 6 2
2 6 9
2 1 6
5 5 8
5 6 1]
B = 5×3
6 6 2 2 6 9 2 1 6 5 5 8 5 6 1
C = {6 6 2;
2 6 9;
2 1 6;
5 5 8;
5 6 1}
C = 5×3 cell array
{[6]} {[6]} {[2]} {[2]} {[6]} {[9]} {[2]} {[1]} {[6]} {[5]} {[5]} {[8]} {[5]} {[6]} {[1]}
D = {6 6 2
2 6 9
2 1 6
5 5 8
5 6 1}
D = 5×3 cell array
{[6]} {[6]} {[2]} {[2]} {[6]} {[9]} {[2]} {[1]} {[6]} {[5]} {[5]} {[8]} {[5]} {[6]} {[1]}
isequal(A,B)
ans = logical
1
isequal(C,D)
ans = logical
1
That is, the results is the same with and without the semi-colon
The time that you need the semi-colon is if you are wanting to manually transform a 2D-entry of a data array into a linear entry, such as
F = [6 6 2;2 6 9;2 1 6;5 5 8;5 6 1]
which is getting further and further away from the original request to put a semi-colon at the end of selected lines. If you had a need for something like that, then if the result is going to be less than 10000 characters, the easiest way is take the original 2D array, assign it to a variable (copy and paste it in the command window if you need to) and use mat2str() on the variable, and copy and paste the result. If the result would be more than 10000 characters, then you should probably be seriously questioning whether putting it all into one line is a good idea.
Aryan Ritwajeet Jha
Aryan Ritwajeet Jha 2023년 4월 23일
편집: Aryan Ritwajeet Jha 2023년 4월 23일
Sorry @Image Analyst @Walter Roberson I didn't explain myself clearly and misunderstood the original question. My question is, whether there exists a keyboard shortcut to put a semicolon at the end of a line on which I have my cursor on.
variable = aBitLongerThanUsual____X____LineOfCodeWhichJustHappensToExceedMyScreenCharacterLimit
%I use LiveScript with the Editor on the left and the Outputs to the right.
Imagine that I have my cursor at the X right now and suddendly decide to supress the displayed output for variable.
Currently the only method I know is either naively using the scrollbar to scroll towards the right of the editor window OR put my cursor somewhere on the line and pressing Ctrl+Right, after which I put a ';' at the end.
Image Analyst
Image Analyst 2023년 4월 23일
There is no single keystroke shortcut. You can do two keystrokes with "end" and then ";".
Walter Roberson
Walter Roberson 2023년 4월 23일
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.

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

 채택된 답변

Stephen23
Stephen23 2015년 3월 23일
편집: Stephen23 2015년 5월 22일

0 개 추천

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

Ismaeel
Ismaeel 2015년 3월 23일
편집: Ismaeel 2015년 3월 23일
Thanks Stephen, I got it. Appreciate your suggestion.

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

추가 답변 (0개)

카테고리

질문:

2015년 3월 22일

댓글:

2023년 4월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by