save data in a array

2 次查看(过去 30 天)
elisa ewin
elisa ewin 2017-3-29
回答: Rik 2017-3-29
Hi, I have a problem: I have create this code
for j=1:size(user(4).data(5).idx,1)
if (user(4).data(5).idx(j,1)~=0)
a=Cluster_USERS{4,1}(user(4).data(5).idx(j,1),4)
end
end
now I have:
a =
7
a =
7
a =
7
a =
0
I want a=[ 7 7 7 0], how can I modified the code?

采纳的回答

Rik
Rik 2017-3-29
You forgot a semicolon (the ; sign) to suppress output and a was overwritten each loop itteration.
There is a method to use logical indexing instead of a loop. The code below should work.
a=Cluster_USERS{4,1}(user(4).data(5).idx(:,1)~=0,4);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by