how do i create a function with one of the inputs being cell array

If I'm creating a function called searchGOterms and want the Key_word input to be a cell array, how do I do that? I created the function below but don't know how to specify Key_word as a cell array. Also, I want to check if the Key_word input is legal, meaning it is not an empty array and if it is to display an error message. Do I use the error function? Thank you!
function [] = searchGOterms(goTerms_fname,Key_word)

 채택된 답변

the cyclist
the cyclist 2014년 2월 11일

0 개 추천

You could probably use some combination of the following commands to do what you need:
  • iscell
  • isempty
  • nargin

댓글 수: 3

Thank you, but to declare Key_word as a cell array input in the function,do I need to put brackets around it like this?:
function [] = searchGOterms(goTerms_fname,{Key_word})
which gave me an error message.
Types don't generally need to be declared in MATLAB. Just pass in a cell array from the calling function, and the function will "know" it is a cell array. [Or you can check with iscell().]
If you are creating a cell array from scratch, then there is the cell() command [e.g. c = cell(2,3)] that will create the array framework to be filled in.
great, thank you so much. that helps.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

질문:

2014년 2월 11일

댓글:

2014년 2월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by