MATLAB Answers

Merging calculated solution elements cell arrays into a single column cell array

1 view (last 30 days)
Dear All,
Please, I have a major issue which I would greatly appreciate some assistance. I have calculated a 3x1x108 cell array solution. Each of the 108 elements is a numeric array with dimensions ranging from val (:,:,1) to val (:,:,108). I would like to merge all the calculated element’s solution into a single 3x1 column array.
Thank you so much for your help.
Val (:,:,1) = 1.0e+04 *
0.000000022979506 - 0.000000036470490i
0.002185443408772 - 0.052463050512697i
2.289129333615808 + 5.029468816352341i
Val (:,:,2) = 1.0e+04 *
-0.000001404857395 + 0.000002447418100i
-0.021924555135876 - 0.020324520317864i
1.557775455827619 + 0.915119490385055i
Val (:,:,3) = 1.0e+04 *
-0.000003885746464 - 0.000002190311736i
-0.534013981410952 - 0.242903162743672i
1.943318570895146 + 2.219598861090568i
Val (:,:,108) = 1.0e+04 *
-0.000000014195745 - 0.000000010788638i
-2.278194863009318 + 0.437249050543058i
1.969494482063662 + 0.559354184163361i

Accepted Answer

Mohammad Sami
Mohammad Sami on 24 Jun 2021
You can try using cell2mat to convert the cells into a matrix.
a = num2cell(randi(3,[3 1 108]));
b = cell2mat(a);
b = permute(b,[3 1 2]);
b
b = 108×3
2 2 3 2 1 2 1 1 3 2 1 2 1 3 2 1 1 3 2 1 1 1 2 3 3 3 3 1 3 1
  1 Comment
Mohammed Abdullahi
Mohammed Abdullahi on 25 Jun 2021
The goal is to obtain single 3x1 matrix from 108x1 matrix. what is the most appropriate way to achieve that?

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!