what does the error mean for "Function definitions are not permitted in this context."?
Afficher commentaires plus anciens
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
1 commentaire
Jan
le 23 Jan 2018
Réponses (1)
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
Catégories
En savoir plus sur Migrate GUIDE Apps dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!