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!