MATLAB Online does not run script properly
Show older comments
I ran the following script (which I named draft.m) through MATLAB Online:
clear;
fun = @(x, b) (b-7)*(b+5)*x.^2-2*x+3;
brange = -8:0.1:10;
fmin = [];
for b = brange
end
and got the following error message:
>> draft
Error: File: draft.m Line: 6 Column: 1
At least one END is missing. The statement beginning here does not have a matching end.
But if I remove the line
fmin = [];
then it works. Did I miss something? I suppose defining an empty array shouldn't fail the for loop, should it? Thank you very much in advance for any comments that you may have.
3 Comments
Martin
on 10 Apr 2024
Moved: Dyuman Joshi
on 10 Apr 2024
How to convert a matrix from real numbers into a Modulo, for example, how would I convert the following matrix into modulo 7?
M = [7 3 7; 1 0 9; 7 2 8]
Dyuman Joshi
on 10 Apr 2024
@Martin, Have you tried searching on the internet or on this forum for the same?
Cris LaPierre
on 10 Apr 2024
This is unrelated to this question. Please ask this in a new question.
Answers (1)
Code runs without error for me. I can also run it here without error. Perhaps try again? If it happens again, perhaps there are more details you can share about what you are doing?
clear;
fun = @(x, b) (b-7)*(b+5)*x.^2-2*x+3;
brange = -8:0.1:10;
fmin = [];
for b = brange
end
b
8 Comments
Kiam Heong Kwa
on 9 May 2022
Kiam Heong Kwa
on 9 May 2022
Torsten
on 9 May 2022
And the error message is the one you posted above:
Error: File: draft.m Line: 6 Column: 1
At least one END is missing. The statement beginning here does not have a matching end.
?
Kiam Heong Kwa
on 9 May 2022
Just a guess:
What if you use
fmin = [fmin,fval];
instead of
fmin(end+1) = fval;
or even better:
fmin = zeros(numel(brange),1)
for b = brange
f = @(x) fun(x, b);
[crit, fval] = fminbnd(f, -6, 6);
fmin(b) = fval;
end
Kiam Heong Kwa
on 9 May 2022
Cris LaPierre
on 9 May 2022
The full code runs fine for me.
Kiam Heong Kwa
on 9 May 2022
Categories
Find more on MATLAB 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!