save data in for loops
1 view (last 30 days)
Show older comments
Hi everyone,
I am trying to save my data into a matrix, each time two columns as X and Y.
but the codes don't work.
Can anyone explain and help?
Thanks a lot.
coordinate= zeros();
fora=1:21
Z=[X Y];
X = snakes{1,a}.x;
Y = snakes{1,a}.y;
coordinate((a),:)= Z;
end
Accepted Answer
Ajay Kumar
on 11 Feb 2020
Edited:Ajay Kumar
on 11 Feb 2020
Yes, You are trying to assign 2 matrices of different size. Try this:
coordinate= zeros(41,1);
fora=1:21
X = snakes{1,a}.x;
Y = snakes{1,a}.y;
% Z=[X Y];
ifa == 1
coordinate(:,end)= X;
coordinate(:,end+1) = Y;
else
coordinate(:,end+1)= X;
coordinate(:,end+1) = Y;
end
end
coordinate
size will be 41x42. For each a, we have 41x2 which means for 21 a's it will be 41x42.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!