executing a loop most probably while
이전 댓글 표시
I have created a function which groups a vast data. Here, for simplicity, I have used 20 data points. group(x,y) creates the required group (g1) and the next 'for' loop removes the elements of this group to create a new dataset. Again the group(x,y) creates the next group(g2) and the initial dataset is modified. I want to create a loop which will execute this till the dataset has zero elements,i.e. all the elements are grouped with group numbers,g1,g2 etc. I have tried to use while loop but I cannot change the group names, hence the error. Any help will be appreciated.
x = gallery('uniformdata',20,1,1);
y = gallery('uniformdata',20,1,1);
group(x,y);
g1=ans
for i=1:length(g1)
x(any(x==g1(i,1),2),:)=[];
y(any(y==g1(i,2),2),:)=[];
end
group(x,y);
g2=ans
for i=1:length(g2)
x(any(x==g2(i,1),2),:)=[];
y(any(y==g2(i,2),2),:)=[];
end
댓글 수: 3
Image Analyst
2018년 1월 16일
What is ans? Why doesn't your group() function return anything?
Stephen23
2018년 1월 16일
@Busy Bee:
- Why do you not return any output from group ?
- Do NOT use ans as a variable name.
- Do not try to magically generate variable names g1, g2, etc:
Just use simpler and much more efficient indexing.
Busy Bee
2018년 1월 16일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!