Converting data from two cell arrays in one vector
조회 수: 8 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Rik
2020년 12월 12일
편집: Rik
2020년 12월 12일
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
Gitte
2020년 12월 12일
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
2020년 12월 12일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!