MATLAB Answers

save data in for loops

2 ビュー (過去 30 日間)
yunwei hu
yunwei hu 2020 年 2 月 10 日
編集済み: Ajay Kumar 2020 年 2 月 11 日
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();
for a=1:21
Z=[X Y];
X = snakes{1,a}.x;
Y = snakes{1,a}.y;
coordinate((a),:)= Z;
end

  4 件のコメント

表示 1 件の古いコメント
Stephen Cobeldick
Stephen Cobeldick 2020 年 2 月 10 日
yunwei hu's "Answer" moved here:
Hi there,
x, y and snakes are just data l got from somewhere else and need to evaluate.
the question here is how to get X an Y into two columns of a new matrix.
Ajay Kumar
Ajay Kumar 2020 年 2 月 10 日
what is the format of those?
Could you upload x, y and snakes here.
yunwei hu
yunwei hu 2020 年 2 月 10 日
i uploaded the snakes.
x and y are all inside of it.

サインイン to comment.

採用された回答

Ajay Kumar
Ajay Kumar 2020 年 2 月 11 日
編集済み: Ajay Kumar 2020 年 2 月 11 日
Yes, You are trying to assign 2 matrices of different size. Try this:
coordinate= zeros(41,1);
for a=1:21
X = snakes{1,a}.x;
Y = snakes{1,a}.y;
% Z=[X Y];
if a == 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 件のコメント

サインイン to comment.

その他の回答 (0 件)

サインイン してこの質問に回答します。


Translated by