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

2 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by