How to loop through cell array and apply script to each double?

Hi,
I have a cell array of cell arrays of doubles called "C_512_numeric". I have the script called edit and I want to loop through all columns in the doubles in C_512_numeric and use the column data as input for edit (first argument). I have attached the script.
How would I write this code?

답변 (1개)

Aquatris
Aquatris 2024년 7월 26일
편집: Aquatris 2024년 7월 26일
You can use the cellfun function, where you use your script as the function. Example:
a = {1:3, 200:205, 10:12};
new_a = cellfun(@(x) myfun(x) ,a,'UniformOutput',false);
new_a{:}
ans = 1x3
-2 -4 -6
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 1x6
-400 -402 -404 -406 -408 -410
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 1x3
-20 -22 -24
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
function y = myfun(x)
y = x*(-2);
end

댓글 수: 2

I dont think I quite understand. I am not that familiar with cellfun. Could you kindly show me the script?
The script is within the answer already. What exactly is the part you are struggling with?

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2024년 7월 26일

댓글:

2024년 7월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by