Clear Filters
Clear Filters

save data in a array

1 view (last 30 days)
elisa ewin
elisa ewin on 29 Mar 2017
Answered: Rik on 29 Mar 2017
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?

Accepted Answer

Rik
Rik on 29 Mar 2017
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);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!