- You need to call the function with two inputs: the array and the indices. You only provide the array, hence the error.
- In the routine you changed a varibale name in the line extracted = array2table(extracted)
Why do i keep on getting error 'Not enough input arguments' on calling the function?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to create a table of values of certain lengths (indices stored as indices )from a vector. For that I create an empty table and then later insert these values inside that. This works in the code, but when I try to make a function, it gives an error, "Not enough input arguments."
The working code is given below
clc
clear all
close all
Data= load('array.mat');
array = Data.array
indices = [4 80 99 143 166 197 204 250 295 350 385 400 467 554];
lengthx = length(indices);
lengthy = height(array);
extracted = NaN([lengthy lengthx]);
extracted = array2table(extracted);
for i = 1:lengthx
num = indices(i);
a = array(1:num);
padding = lengthy-height(a);
extracted(:,i)= array2table(padarray(a,padding,NaN,'post'));
end
Now, I try to make a function out of it as
function [extracted] = arrayextraction(Data,indices)
lengthx = length(indices);
lengthy = height(Data);
extracted= NaN([lengthy lengthx]);
extracted= array2table(cumx);
for i = 1:lengthx
num = indices(i);
a = Data(1:num);
padding = lengthy-height(a);
extracted(:,i)= array2table(padarray(a,padding,NaN,'post'));
end
end
When I call the function using the following code, it gives an error of 'Not enough input arguments'. The only difference is something to do with the indices. When I put the indices vector inside the function, it works, but when I put it as input, it gives error. I call the function using the following code
Data= load('array.mat');
array = Data.array
b = arrayextraction(Data);
I ran through the help and documentation, it may be a simple misunderstanding that i cannot figure out and I will appreciate help in this regard.
Thanks
Good day.
0 Kommentare
Akzeptierte Antwort
Karim
am 31 Okt. 2022
See below for the modified version.
There were two issues:
% load the mat file
Data = load(websave('myFile', "https://nl.mathworks.com/matlabcentral/answers/uploaded_files/1174743/array.mat"));
% get the inputs
array = Data.array;
indices = [4 80 99 143 166 197 204 250 295 350 385 400 467 554];
% run the function
[extracted] = arrayextraction(array,indices);
% have a look at the ouput
extracted
% this is the modified function
function [extracted] = arrayextraction(Data,indices)
lengthx = length(indices);
lengthy = height(Data);
extracted = NaN(lengthy,lengthx);
extracted = array2table(extracted);
for i = 1:lengthx
num = indices(i);
a = Data(1:num);
padding = lengthy-height(a);
extracted(:,i)= array2table(padarray(a,padding,NaN,'post'));
end
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!