How can I run a section when there are still errors present in other sections?

I provide my students with a script, which they need to modify. I want them to evaluate the part they have finished but the script will not run because of errors still present in other sections. with 2017a it is possible, with 2017b not.
Example code, the first section (with clear) will not execute because of errors in the code below that.
%% (c) C.M.G. van Leuken, W.L. van de Groep, R.G.P. Ritzen
% Fontys University of Applied Sciences, Mechanical Engineering
% (Fontys Hogeschool Engineering, opleiding Werktuigbouwkunde)
clear all close all clc
%% EXERCISE 3-1 (OPDRACHT 3-1)
% Write down the code to make plots of the V-line (equation 3-9) and M-line (equation 3.10) as a function
% of x.
% (Maak hieronder de plotjes van de D-lijn (vergelijking 3-9) en M-lijn (vergelijking 3-10) als
% functie van x.)
dx = ... % step size (stap grootte)
x1 = ... % first interval (eerste interval)
x2 = ... % second interval (tweede interval)
x3 = ... % third interval (derde interval)
x = [x1 x2 x3]; % combining the intervals (samenvoegen van de intervallen)
D1 = ...
D2 = ...
D3 = ...
D = ... % V-line (D-lijn)
M1 = ...
M2 = ...
M3 = ...
M = ... % M-line (M-lijn)

2 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 9 日
you can make them to test it in live editor
KSSV
KSSV 2018 年 10 月 9 日
Explore the option of run and advance

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

 採用された回答

Image Analyst
Image Analyst 2018 年 10 月 11 日

0 投票

You can highlight the lines of code that are "good/valid" and type the F9 key.
This will always work regardless if there are syntax errors with the other lines.

10 件のコメント

Image Analyst
Image Analyst 2018 年 10 月 12 日
Cor's comment to me moved here since it's not an answer to the original question at the top:
Correct, but when there is any error inside the selected code it is difficult for a new student (= new Matlab user) to find the error as no line is indicated. run section, or run, indicate the error location.
Image Analyst
Image Analyst 2018 年 10 月 12 日
True, but they do know that it's in the highlighted lines. They will ultimately need to fix all syntax errors anyway so if they can't find out which line it is, then they could either run the whole thing, or copy the highlighted lines to another script and run them there.
Michael Reshko
Michael Reshko 2019 年 3 月 29 日
This is way too awkward and is surely not the way the tool should function. In the previous versions, I execute a section (Ctrl + Enter) regardless if other sections contained any errors. In R2018b this no longer works for me.
How do we get back the error-free execution of a section without having to highlight all lines of code in the section?
Sam Bell
Sam Bell 2020 年 3 月 6 日
I agree with Michael
Marilee Nugent
Marilee Nugent 2021 年 1 月 8 日
Yes! I was just forced to switch to a newer version because 2015b would not allow me to update the license. Now I discover this problem, and it will cost me a lot of valuable time!!! argh!!! not happy
Image Analyst
Image Analyst 2021 年 1 月 9 日
Well Michael is not entirely incorrect. If you run a section of code like I said (by highlighting and typing F9) it will run regardless if there are errors in any other section.
However if you're in a "section" and then say "Run Section" it will not run that section if there are syntax errors in earlier sections in the program. But you'd have to fix them eventually anyway so go ahead and fix them. Or just comment them out with control-R.
I'm not sure why this would cost you a lot of valuable time. You'd eventually need to fix all your syntax errors anyway to get a completely functioning program, so being able to run sections by the "Run Section" button instead of the F9 key doesn't seem like a big time waster to me.
Travis Briles
Travis Briles 2021 年 7 月 13 日
I genuinely do not understand why this new feature is remotely helpful...
Image Analyst
Image Analyst 2021 年 7 月 13 日
@Travis Briles, what new feature? You aren't talking about F9 are you? That's been around for ages (not new) and I use it in virtually every editing/debugging session I do. It lets you stop at a breakpoint and then change code right at the problem area and try it out without having to start the whole program (your app) over again.
I believe people are complaining of the fact that, previously, one could provide students with a code such as the following (VERY simple example):
%% System matrices
A = [-1 2; 0 -2];
B = [0; 1];
C = [1 0];
D = 0;
sys_ol = ss(A,B,C,D);
%% Select appropriate poles for pole placement
xi = ;
w = ;
lambda = roots([1 2*xi*w w^2]);
K = place(A,B,lambda);
%% Write the state-space representation of the closed-loop system
Ak = ;
Bk = ;
Ck = ;
Dk = ;
sys_cl = ss(Ak,Bk,Ck,Dk);
The students would be able to modify and run each section as they go along during a lab, for example. As the run section functionality is working now, this is impossible. I believe this is why @Marilee Nugent is saying that this will cost valuable time, as virtually ALL code given to students will need to be updated to remove syntax errors. And by updated I mean adding a dummy value, which will make it less clear for the students which rows are "correct" and which are still to be done.
Finally, the feature that @Travis Briles refers to is exactly this new implementation of the run section functionality that checks for code syntax errors. And I agree that I do not see its usefulness, as when I am running a given section I don't care about syntax errors down below. Sometimes I am in the middle of writing a new line of code and need to check the result of a piece of code a bit further up, but as it turns out I cannot run that section because I did not finish to write the new line of code that is 100 lines below and has absolutely no impact on the section I am trying to run.
And I know about F9, but this is not as clean and practical as just running an entire section, which is also good for didactical reasons... Anyway, just thought I would clarify the issue and add my voice to the complaints :)
Niklas
Niklas 2024 年 3 月 13 日
As of March 2024, this seems to be the accepted answer, but I still have trouble running only one section in MATLB 2020b when there are syntax errors in other sections. Is there any advancement on this problem?

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

その他の回答 (4 件)

Adam Campos
Adam Campos 2023 年 6 月 4 日
編集済み: Adam Campos 2023 年 6 月 4 日

1 投票

To clarify, my issue is with the Live Scripts - I'm not sure I understand what the point of 'Run Section' is if it picks up syntax errors in other sections and doesn't run the given section. I have hundreds of scripts with similar type of temporary filler for variables, I know and understand that there are syntax issues because it has temporary filler in the other sections, but this is pretty burdensome that I have to inspect the whole script fix all the errors just to get started. I fully expect an error if I chose 'Run', but not 'Run Section'
Jupyter Notebooks let you run a section and leave the rest for development, which is what I was expecting.

2 件のコメント

Niklas
Niklas 2024 年 3 月 13 日
I have exactly the same problem and am seriously considering of rewriting everything in Python Jupyter Notebooks.
Adam Campos
Adam Campos 2024 年 3 月 16 日
If you have to transition them I did bulk find and replace in a text editor, like VS Code and converted them over....I know this doesn't solve your problem, but easier than trying to fix scripts directly within MATLAB.

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

Stephen Ofori
Stephen Ofori 2023 年 10 月 18 日

1 投票

Hi Kindly insert ‘Section break’ at the various sections you want to run separately. Go to Live Editor Tab > Section > Section Break
Cor van Leuken
Cor van Leuken 2018 年 10 月 11 日

0 投票

Unfortunately, both options does not do it. We have decided to make the script syntax correct. So not dx= … But dx = dummy; anyway, thanks for your help
Cor van Leuken
Cor van Leuken 2021 年 7 月 14 日

0 投票

It might not usefull to experienced users, but a lot of people (students) still need to learn it.
we do not have a separate course 'Matlab' but we are using Matlab in another course.
in that course the student gets an incomplete script file which need to be changed.
in the past, all parts needed to change were indicated like:
Torque=...;
...
now it is indicated as
Torque=dummy;
dummy
and the student needs to add the correct formula and other statements at every line the text dummy appears

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by