Pass Cell array to matlab function via Bash script

조회 수: 9 (최근 30일)
Oliver Warrington
Oliver Warrington 2019년 3월 5일
답변: Chang 2021년 11월 30일
I have a Matlab function that I want to take a cell array as it's input and do something to each element:
function RegSPM(Subjects)
for s = 1:length(Subjects)
display(s)
end
end
and I have a bash script that creates a Subjects array and I want to pass this to the RegSPM function:
Subjects=('S01' 'S02')
matlab -r "RegSPM($Subjects)"
But Matlab doesn't get the list and instead gives the error:
RegSPM(S01,)
Error: Invalid expression. When calling a function or indexing a variable, use
parentheses. Otherwise, check for mismatched delimiters.
Any body have any ideas on how to do this properly? I think I'm missing something.
Thank you.

답변 (2개)

Patel Mounika
Patel Mounika 2019년 3월 12일
Try using curly braces {}, instead of smooth parentheses () to create the Subject cell array.
Subjects={'S01','S02'};
You can also refer to the below thread.
Hope this solves.
  댓글 수: 1
Oliver Warrington
Oliver Warrington 2019년 3월 12일
I tried using:
Subjects={'S01','S02'};
matlab -r "RegSPM($Subjects)"
But unfortunately it does not seem to think of it as a list input to the function and I get the error:
Undefined function or variable 'S01'.
Thank you for trying Patel!

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


Chang
Chang 2021년 11월 30일
I had the same issue and I tried below.
It worked.
Subjects={"'S01'","'S02'"}

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by