Nested function: FUNCTION keyword use is invalid here. This might cause later messages about END
显示 更早的评论
I have a function as seen below and am trying to create a nested function:
function [ sortedArray ] = mergeSort( doubleArray )
%UNTITLED2 Summary of this function goes here
% doubleArray: a 1 by N unordered double array to be sorted
% sortedArray: the sorted array of soubleArray
% mergeSort: splits the array into two sub-arrays, recursively sorts the
% two sub-arrays, and then combines the two sorted sub-arrays
A=length(doubleArray);
if A==1
sortedArray=doubleArray;
else
mid=floor(A/2);
array1=mergeSort(doubleArray(1:mid));
array2=mergeSort(doubleArray(mid+1:end));
function combinedArray=combine2Arrays(array1,array2)
combinedArray=[array1, array2];
combinedArray=sort(combinedArray);
end
end
However, I keep getting an error: FUNCTION keyword use is invalid here. This might cause later messages about END.
Does this mean my nested function is incorrect? It is in a function (.m) file NOT script.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!