How can I convert data of 2 cells into one vector?

조회 수: 3 (최근 30일)
Simon Peeters
Simon Peeters 2020년 12월 21일
답변: Jan 2020년 12월 21일
I have this for loop:
min = zeros(1,4);
max = zeros(1,4);
vector = zeros(1,4);
for i = 1:4
min(1,i) = min(time{1,i});
max(1,i) = max(time{1,i});
vector(1,i) = [min(1,i); max(1,i)]; % I tried this but it does not work
end
I want to create a matrix with on the first place a vector with [min(1,1); max(1,1)] and on the second place a vector [min(1,2); max(1,2)] ,... So in each cell of the matrix I want a vector of 2 numbers.
Can someone help me? Thanks!

답변 (1개)

Jan
Jan 2020년 12월 21일
Do not use the names of the built-in functions "min" and "max" as names of variables, because this causes troubles frequently.
[min(1,i); max(1,i)] is a [2 x 1] vector, but vector(1,i) is a scalar. You cannot assign a vector to a scalar. Maybe you want:
vector = zeros(2, 4);
...
vector(:, i) = [min(1,i); max(1,i)];

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by