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!