MATLAB Answers

## how to sort in a loop?

Asked by Shubham Mohan Tatpalliwar

### Shubham Mohan Tatpalliwar (view profile)

on 23 Oct 2018
Latest activity Answered by Jan

### Jan (view profile)

on 24 Oct 2018
Accepted Answer by Jan

### Jan (view profile)

the main question is solved but i have another question.
for i= 1:42
for j=0:100:4100
A(i)=sort(Achsemoment==(j) & Achsemoment<=(j+1));
end
end
i am having a vector of length 100000
which contains values from 0 to 4200
and i want to sort them all in step of 100 in different variables...
so tried this but not getting correct code

#### 4 Comments

Show 1 older comment
Shubham Mohan Tatpalliwar

### Shubham Mohan Tatpalliwar (view profile)

on 24 Oct 2018
I want 42 vectors like a1,a2,a3....a42
and each containing logical values or real values from o to 100, 100 to 200....4100 to 4200
Abdul Rehman

### Abdul Rehman (view profile)

on 24 Oct 2018
%Try like this:
if true
k=1;
for i=1:42
for j=1:100
a(i)=sort(Achsemoment(k));
k=k+1;
end
Sort:
Think so it's helpful, thank..!
Jan

### Jan (view profile)

on 24 Oct 2018
I want 42 vectors like a1,a2,a3....a42
This is a very bad idea, which is discussed daily in this forum. Please read: Why and how to avoid the dynamic creation of variables.

Sign in to comment.

## 1 Answer

Answer by Jan

### Jan (view profile)

on 24 Oct 2018
Accepted Answer

It is not clear what you want to sort. I do not see any reason to sort something. What about:
A = cell(1, 42);
for i = 1:42
for j = 0:100:4100
A{i} = (j <= Achsemoment & Achsemoment <= j+1);
end
end

#### 0 Comments

Sign in to comment.