Cell array as input function

조회 수: 2 (최근 30일)
Gitte
Gitte 2020년 12월 12일
댓글: Ive J 2020년 12월 12일
I have a certain function that I need to use:
[t3_1_HR,q3_1_HR,qd3_1_HR,Tact3_1_HR,TSRS3_1_HR] = SimulatePendulumTest(m, kF, kdF, d, Tb, 1, tspanHR);
And I have a cell array with different tspanHR's (every row is a subject and each column is the number of HR files per subject). I want to know every outcome of the function for the different tspanHR values. How can I do this?
Thank you very much!
  댓글 수: 1
Rik
Rik 2020년 12월 12일
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.

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

답변 (1개)

Ive J
Ive J 2020년 12월 12일
편집: Ive J 2020년 12월 12일
You can use cellfun to apply your function to each cell.
[t3_1_HR, q3_1_HR, qd3_1_HR, Tact3_1_HR, TSRS3_1_HR] = ...
cellfun(@(x)SimulatePendulumTest(m, kf, kdF, d, Tb, 1, x), YourCellArray, 'uni', false);
  댓글 수: 4
Rik
Rik 2020년 12월 12일
It does, but your function should do that as well. cellfun does not automatically skip empty elements.
A=rand(2,3);
cellfun(@(x) size(A,x),{1,[]},'UniformOutput',false)
Error using size
Dimension argument must be a positive integer scalar or a vector of positive integers.

Error in solution (line 2)
cellfun(@(x) size(A,x),{1,[]},'UniformOutput',false)
Ive J
Ive J 2020년 12월 12일
Oops! I see, you are absolutely right, I assumed user function in the simplest form.
A = rand(2, 3);
input = {1, []};
cellfun(@(x) size(A, x), input(~cellfun(@isempty, input)))

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

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by