how to run the matlab code step-by-step?

Dear sir/madam,
I need to run the matlab code step-by-step, and also see what is happening in the code or the variables. How can I do this? Looking forward to hearing from you soon.
Thanking you, BSD

回答 (3 件)

Arnaud Miege
Arnaud Miege 2011 年 7 月 26 日

3 投票

Use the debugger. See Editing and Debugging MATLAB Code in the documentation for more details.
HTH,
Arnaud

1 件のコメント

Jan
Jan 2011 年 7 月 26 日
@Arnaud: Thanks for this important answer. Although it might seem so obvious, there are a lot of questions in this forum, which could be avoided, if the user knows how to apply the debugger. +1

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

Andreas Goser
Andreas Goser 2011 年 7 月 26 日

1 投票

Many users also prefer not line by line, but a bit larger chunks. Look for "Cell Mode".

3 件のコメント

bsd
bsd 2011 年 7 月 26 日
@Andreas Goser,
Thanks for the reply. What is this cell mode? I a new to matlab. Please brief it.
Thanking you,
BSD
Jessica
Jessica 2011 年 7 月 26 日
編集済み: Walter Roberson 2025 年 2 月 9 日
@bsd, If you put %% on a line, you'll notice that it separates the code into pieces. You can separate chunks of your code by putting %% in various places. Then, if you want to just run one cell, you can simply hit ctrl+enter (or right click and then click "Evaluate Current Cell").
Ex:
%% First cell
x = 1:2:10 ;
y = 5:-1:1 ;
z = x + y ;
%% Second cell
figure(1)
plot3(x,y,z)
When you ctrl+enter while your cursor is in the first cell, it only defines the variables. Then, when you ctrl+enter while in the second cell, it only plots the figure. I hope that helps clarify @Andreas Goser's answer.
Arnaud Miege
Arnaud Miege 2011 年 7 月 27 日
If you read the section of the documentation I mentioned in my answer, you'll see there is a part entitled "Evaluating Subsections of Files Using Code Cells".

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

Daniel Shub
Daniel Shub 2011 年 7 月 27 日

1 投票

There is a recent blog post by Loren http://blogs.mathworks.com/loren/2011/04/28/is-there-an-echo-out-there/ about the echo command. Cell mode and the debugger are nice, but I think a lot of us have forgotten (or never knew) the power of echo.

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

質問済み:

bsd
2011 年 7 月 26 日

編集済み:

2025 年 2 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by