Nested for loop and cell arrays

I have a cell array, A, containing 40 cells, each of different sizes. I need to use each of these cells (let's call one, A1(1x101)) in a function, which should loop through all values of A1 and output EACH iteration of the function to a NEW cell array,B, I then need to SUM ALL the arrays within B and output that array to a NEW cell array C. This needs to repeat for ALL 40 cells of A.
So I need to use the cells in A, to make a cell array B, and then use the arrays in B to make C, this whole loop should repeat 40 times for each array in A.
The first loop should use the cell A1 to output a single array,C1, into cell array C. The second loop should use A2, to output an array C2, into cell array C and so on.
The cell array B should be overwritten for each loop.
Apologies if it's not clear, I'm struggling to write the code for it quite a bit.

Antworten (1)

Jos (10584)
Jos (10584) am 4 Jan. 2018

0 Stimmen

help cellfun

1 Kommentar

mathman
mathman am 4 Jan. 2018
Bearbeitet: mathman am 4 Jan. 2018
I've tried this but I'm having trouble implementing my function, it has 9 inputs, of which only one is changed by the content of the cell array.
So I've done:
B = cellfun((@myfunction(1,2,(-2:0.05:2),(0:0.05:4),3,THIS_CHANGES,4,5,(0:1e-08:4e-06))), A, 'UniformOutput', false');
Which returns the error:
Error: Unbalanced or unexpected parenthesis or bracket.
But I can't find where the parenthesis is unbalanced.
I'm also not 100% sure that this would do what I want it to either.As I understand it, it would output a cell array,B, where the arrays contain the outputs of myfunction for each cell of A.
So either B would be extremely large (it would have to contain each output array of each value of each cell of A) or it wouldn't do what I want it to.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 4 Jan. 2018

Bearbeitet:

am 6 Jan. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by