how to sort in a loop?

조회 수: 5 (최근 30일)
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar 2018년 10월 23일
답변: Jan 2018년 10월 24일
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
Abdul Rehman
Abdul Rehman 2018년 10월 24일
편집: Abdul Rehman 2018년 10월 24일
%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 2018년 10월 24일
편집: Jan 2018년 10월 24일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2018년 10월 24일
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개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by