4 views (last 30 days)
Show older comments
Carly Hudson on 28 Feb 2022
-
-
Link
Direct link to this question
https://www.matlab.com/matlabcentral/answers/1659810-creating-empty-cell-array-with-function
Commented: AndresVar on 1 Mar 2022
function link_set = build_links(link_vectors);
% Use the 'cell' 'and 'size' commands to create an empty cell array the
% same size as link_vectors, named 'link_set'
link_set = cell(1,size(link_vectors));
I am working on a project in MATLAB Grader and it has been a while since iv'e used MATLAB. I'm having trouble creating this array and I keep getting the "Not enough input arguments." error. Any help or guidamce would be greatly appreciated.
3 Comments Show 1 older commentHide 1 older comment
Show 1 older commentHide 1 older comment
AndresVar on 28 Feb 2022
Direct link to this comment
https://www.matlab.com/matlabcentral/answers/1659810-creating-empty-cell-array-with-function#comment_2010620
- "not enough input arguments": your function has 1 argument so you have to call it with 1 input. For example build_links(x), where x is something you defined earlier
- cell(1,size(...))) will give error. You want to make a cell(size(x))
Carly Hudson on 28 Feb 2022
Direct link to this comment
https://www.matlab.com/matlabcentral/answers/1659810-creating-empty-cell-array-with-function#comment_2010630
function link_set = build_links(link_vectors)
% Take a set of link vectors and augment each with a zero vector representing
% the base of the link
%
% Input:
%
% link_vectors: a 1xn cell array, each element of which is an mx1 vector
% from the base to end of a link, as seen in its *local* coordinate
% frame
%
% Output:
%
% link_set: a 1xn cell array, each element of which is a mx2 matrix whose
% first column is all zeros (representing the base of the link in its
% local frame) and whose second column is the link vector (end of the
% link) in its local frame
%%%%%%%%%%%%%%
% Use the 'cell' 'and 'size' commands to create an empty cell array the
% same size as link_vectors, named 'link_set'
%%%%%%%%%%%%%
% Loop over the vectors in link_vectors, constructing a matrix whose
% first column is all zeros and whose second column is the link vector,
% and saving this matrix in the corresponding column of link_set
end
this is the whole prompt. im just confused because link_vectors is something that already exists. so i dont know why i cant just call it in when i define link_set
AndresVar on 1 Mar 2022
Direct link to this comment
https://www.matlab.com/matlabcentral/answers/1659810-creating-empty-cell-array-with-function#comment_2012750
I see, well here is an example, for n=2, m=3. This function just creates a cell array the same size as the input, which is the first part of what your function should do.
anInput = {[1;2;3],[4;5;6]}; % variable to use as an input
size(anInput)
ans = 1×2
1 2
anOutput = theFunction(anInput); % function call returns an output
size(anOutput) % the function made an output with the same size as the input
ans = 1×2
1 2
function theOutput = theFunction(theInput) % function definition block
theOutput = cell(size(theInput));
%%% make a matrix
end
Btw to be clear in your actual example: link_vectors is an input, you call build_links, and it returns a copy of link_set.
Sign in to comment.
Sign in to answer this question.
Answers (1)
KSSV on 28 Feb 2022
It seems you are straight away running the function. You need to provide the inputs to the function and then call the function.
link_vectors = rand(1,3) ; % define your input variables
% now call the function
link_set = build_links(link_vectors);
1 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
Carly Hudson on 28 Feb 2022
Direct link to this comment
https://www.matlab.com/matlabcentral/answers/1659810-creating-empty-cell-array-with-function#comment_2010635
function link_set = build_links(link_vectors)
% Take a set of link vectors and augment each with a zero vector representing
% the base of the link
%
% Input:
%
% link_vectors: a 1xn cell array, each element of which is an mx1 vector
% from the base to end of a link, as seen in its *local* coordinate
% frame
%
% Output:
%
% link_set: a 1xn cell array, each element of which is a mx2 matrix whose
% first column is all zeros (representing the base of the link in its
% local frame) and whose second column is the link vector (end of the
% link) in its local frame
%%%%%%%%%%%%%%
% Use the 'cell' 'and 'size' commands to create an empty cell array the
% same size as link_vectors, named 'link_set'
%%%%%%%%%%%%%
% Loop over the vectors in link_vectors, constructing a matrix whose
% first column is all zeros and whose second column is the link vector,
% and saving this matrix in the corresponding column of link_set
end
this is the whole prompt. im just confused because link_vectors is something that already exists. so i dont know why i cant just call it in when i define link_set
Sign in to comment.
Sign in to answer this question.
See Also
Categories
MATLABGraphicsFormatting and AnnotationAxes AppearanceCombine Multiple PlotsSubplots
Find more on Subplots in Help Center and File Exchange
Tags
- cell
- size
- array
- cell array
- dynamics
- function
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office