Hi !
I want to store and append tables data in a for loop. below is the part of code.
using the k as a counter, it stores start and fin values in a vector. but I don't know how to store rng values and tables (and append tables in each loop)
When I am using rng(k) = .... I get this error :
"Unable to perform assignment because the size of the left side is 1-by-1316 and the size of the right side is 1-by-1253 "
and when I use rng and T (as below), it overwrites the data within each loop.
Can someone please help?
% vec,Rep,Pos = some data
k = 1
for i = 1:length(vec)
time = (data(vec(i+1)));
if time >= 6
start(k) = vec(i);
fin(k) = vec(i)+1;
%Question part
rng = start(k):fin(k);
T = table(data.Rep(rng),data.Pos(rng))
k = k+1;
end
end

 Réponse acceptée

KSSV
KSSV le 11 Sep 2020
% vec,Rep,Pos = some data
X = cell([],1) ; Y = cell([],1) ;
k = 1
for i = 1:length(vec)
time = (data(vec(i+1)));
if time >= 6
start(k) = vec(i);
fin(k) = vec(i)+1;
%Question part
rng = start(k):fin(k);
% T = table(data.Rep(rng),data.Pos(rng))
X{k} = data.Rep(rng) ;
Y{k} = data.Pos(rng) ;
k = k+1;
end
end
X = cell2mat(X) ;
Y = cell2mat(Y) ;
T = table(X,Y) ;

2 commentaires

Mahla Bakhshi
Mahla Bakhshi le 11 Sep 2020
Thank you so much!
But since some other arithmetic operations,comparisons,etc (for X{k} Y{k} values within the inner loop ) is required, is there any other way than cell format?
rng = start(k):fin(k);
The above line may have different number of indices, so to store them every time we have to use a cell. If they have same number of indices you can replace them with a marix. You need not to worry about your arithmetic operations, you can carry them as usual. You need to use flower braces {} for acessing cells. Read about them.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by