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

2 visualizaciones (últimos 30 días)
Simon Peeters
Simon Peeters el 21 de Dic. de 2020
Respondida: Jan el 21 de Dic. de 2020
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!

Respuestas (1)

Jan
Jan el 21 de Dic. de 2020
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)];

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by