How to fix code?

3 ビュー (過去 30 日間)
John Foster
John Foster 2013 年 11 月 1 日
コメント済み: Image Analyst 2020 年 4 月 18 日
I am using matlab for the first time. When I make a mistake or a fat finger but do not catch the mistake before hitting enter, is there a way to go back and fix this? My teacher says he does not know of a way other than re typing entire program again. Seems odd that if you get all the way through your program and there is a typo that you have to completely reenter all code.
Thanks!

採用された回答

Image Analyst
Image Analyst 2013 年 11 月 1 日
You are entering your text into a text editor window aren't you? You're not just typing a bunch of lines into the command window are you? So if you're in the text editor, you just make any changes and then hit F5 or click the green triangle. If it's running and you need to stop it early, type control-c. If you hit a 4 and really wanted a 2, just type backspace to get rid of the 4 and then type 2. These are my guesses because you've confused two of us now as to what you actually mean. I'm sure you've used a word processor before or typed things into the computer so I don't really know what the issue is, because this is so basic.
  2 件のコメント
Pawan Khanal
Pawan Khanal 2020 年 4 月 18 日
編集済み: Pawan Khanal 2020 年 4 月 18 日
how about writing in command line ???
Image Analyst
Image Analyst 2020 年 4 月 18 日
No, I would not recommend typing an entire program into the command line. I don't even know if it's possible. You need to write your code into a script. Once done, you can then run your function from the command line if you pass in the required input arguments.

サインインしてコメントする。

その他の回答 (3 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 1 日
You can undo by typing ctrl+z
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 1 日
Jhon commented
So if the error is at the beginning of the program will ctrl+z get rid of all code after the mistake or just the mistake? By mistake I mean I enter a 4 instead of a 2, just a fat finger.
Thanks,
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 1 日
This is not clear for me, can you explain what you mean by go back and fix the error, maybe I misunderstood you

サインインしてコメントする。


John Foster
John Foster 2013 年 11 月 1 日
OK, thank you. Like I said I figured there had to be a way but the professor said the only way was to clear the page and retype everything. This is very time consuming. I have 9 exercises to do and they are close to the same code. It would save me some time if I can just change portions of the code instead of re typing the whole thing. Thanks for your replies!!
  4 件のコメント
John Foster
John Foster 2013 年 11 月 3 日
The way we were shown was to enter in the command window. I will look for the text editor.
Image Analyst
Image Analyst 2013 年 11 月 3 日
John, entering it into the command line is not for multiple lines of code unless you want the problem of having to hit up arrow or retyping. Virtually everyone uses text windows unless it's for just a line or two. If using the text editor works for you, and I helped you discover this, mark my answer (not yours) as Accepted. Thanks.

サインインしてコメントする。


per isakson
per isakson 2013 年 11 月 3 日
編集済み: per isakson 2013 年 11 月 3 日

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by