Converting data from two cell arrays in one vector

8 vues (au cours des 30 derniers jours)
Lotte
Lotte le 12 Déc 2020
Commenté : Rik le 12 Déc 2020
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!

Réponses (1)

Rik
Rik le 12 Déc 2020
Modifié(e) : Rik le 12 Déc 2020
Je zou je klasgenoot kunnen vragen, ik heb gisteren bijna de zelfde vraag beantwoord: link.
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 commentaires
Gitte
Gitte le 12 Déc 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
Rik le 12 Déc 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by