concatenation from 2 differents cell arrays

1 Ansicht (letzte 30 Tage)
AlexDiz
AlexDiz am 9 Mai 2016
Bearbeitet: Stephen23 am 9 Mai 2016
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 Kommentare
Stephen23
Stephen23 am 9 Mai 2016
Bearbeitet: Stephen23 am 9 Mai 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.
AlexDiz
AlexDiz am 9 Mai 2016
yes you are right, I have modified the message, these are cell array thank you

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 9 Mai 2016
Bearbeitet: Stephen23 am 9 Mai 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:
  1 Kommentar
AlexDiz
AlexDiz am 9 Mai 2016
thank you ! it works perfectly exactly what I wanted

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by