Info
此问题已关闭。 请重新打开它进行编辑或回答。
is there a way of scanning an array to find out what there is in there so i dont reinsert the same variable in there?
1 次查看(过去 30 天)
显示 更早的评论
i have an array numbers = [];, i want to create a while loop which inserts numbers into the array. i do not want repeated numbers in the array so if the number already exists i do not want to insert it into the array.
2 个评论
Stephen23
2015-3-13
Doing this in a loop might not be the best solution. If you gave a little more information then we could recommend alternative ways that might be neater and faster. You could tell us where these numbers are coming from, their dimensions and what code is executed in the loop. Best would be if you actually uploaded your code, then we could read through it and try it out.
回答(2 个)
Adam
2015-3-13
find( myArray == newNumber, 1 );
If that returns true the number is already there, if not it isn't.
0 个评论
Adam
2015-3-17
In response to your latest comment...
C = setdiff(A,B,'rows');
should do what you want, assuming your pse array also has 2 columns and that you wish to remove rows from A (your dimensions array) in which the pair of values matches your pse array.
Is your pse array just 1x2 or does it have multiple pairs?
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!