Converting data from two cell arrays in one vector
8 views (last 30 days)
Show older comments
I want to convert data from two cell arrays into a new cell array with in each cell a vector of the combined cell arrays values.
So I want to have a new cell array, with in each cell the corresponding values Bmin_HR and Bmax_HR, like [min max]. Thus, we want a 10x5 cell array, with in each cell the vector of the minimum and maximum (values of min and max can be find in Bmin_HR and BmaxHR).
Thanks in advance!
0 Comments
Answers (1)
Rik
on 12 Dec 2020
Edited: Rik
on 12 Dec 2020
Continuing in English: that should be easy to adapt to find the minimum value as well.
You can't convert the cell array to a double because not every cell has a value. If you choose a default value (like 0 or NaN) you can:
Bmax_HR(cellfun('isempty',Bmax_HR))={NaN};
cell2mat(Bmax_HR)
4 Comments
Gitte
on 12 Dec 2020
It worked! But we still don't find how we can make a matrix with a vector in every cell. The vector must have the value of (1,1) in Bmin_HR and the value of (1,1) in Bmax_HR. So that we have a matrix with in every cell [Bmin Bmax].
Rik
on 12 Dec 2020
You can even combine that into 1 call:
minmax=cellfun(@(x) [min(x) max(x)],data,'UniformOutput',false);
Note that you will not be able to convert that to a double of the same size, as you can only have 1 value in each element of a double. Cell arrays allow you to have a single variable in each element.
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!