what does the error mean for "Function definitions are not permitted in this context."?

clc; close all; clear all; levels = 5; im=imread('C:\Users\netuser\Desktop\project ssf\ssf.jpg'); function [gaussout] = gauss_pyramid(im, levels) gaussout = cell(1,levels+1); gaussout{1} = im; subsample = im; figure(1); imshow(im); for i = 2 : levels+1 subsample = reduce(subsample); gaussout{i} = subsample; figure{i}; imshow(gaussout{i}); end end

Antworten (1)

Jan
Jan am 23 Jan. 2018
Bearbeitet: Jan am 23 Jan. 2018
You can save code in two kind of files: scripts and functions. Functions start with the keyword "function" and if this is missing, the file is a "script".
Functions have the advantage, that they have their own workspace (set of locally used variables), while scripts share the workspace with the caller. This makes the sharing of variables easier, but more dangerous, because a script might modify a variable used in the caller, but this is not visible during reading the source code.
Since Matlab R2016b you can define functions inside script files, but for older versions, functions could be defined in function files only. You cannot define a function in the command window.
The code can be simplified:
function gaussout = gauss_pyramid(im, levels)
gaussout = cell(1, levels+1);
for k = 1 : levels+1
gaussout{k} = im;
figure(k);
imshow(im);
im = reduce(im);
end
end

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 23 Jan. 2018

Bearbeitet:

Jan
am 23 Jan. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by