concatenation from 2 differents cell arrays
1 view (last 30 days)
Show older comments
Hello everyone,
I am trying to find an answer on the forum to my problem but I don't find any solution, so here is my problem. As I am a beginner the solution maybe very simple.
I'm processing data from experiment and at one point I have two cell arrays that I want to concatenate considering that the length of the cell can vary from one set of data to another.
for example:
bloc_base contains seven 3-D matrix (x,z,t) and,
bloc_fix contains seven 3-D matrix (x,z,t)
for a known set of data I can do :
new_vector = cat(3, bloc_base{1}, bloc_fix{1},bloc_base{2}, bloc_fix{2},...,bloc_base{7}, bloc_fix{7});
the number of 3-D matrix contained in the cell array can vary from one set of data to another so I try to write a script that can take this info into account to concatenate the data into a new vector. I have tried to use a for loop but I didn't manage to get good result...
If you have any ideas !
thanks
Alex
2 Comments
Stephen23
on 9 May 2016
Edited: Stephen23
on 9 May 2016
@AlexDiz: you write that you "have two structures array", but then you use cell array indexing in your example. These are two very different things! Communicating on this forum is a lot easier when everyone uses the correct terminology: can you please check and confirm if you are using a structure or a cell array.
Accepted Answer
Stephen23
on 9 May 2016
Edited: Stephen23
on 9 May 2016
You don't give sizes of bloc_base and bloc_fix, but for your cell arrays (?) you could try something like this:
C = [bloc_base(:)';bloc_fix(:)'];
out = cat(3,C{:});
Here is a complete working example:
>> A = {[1,2],[3,4],[5,6]};
>> B = {[9,8],[7,6],[5,4]};
>> C = [A;B];
>> cat(3,C{:})
which uses this feature to use the cell array elements as separate input arguments:
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!