Need to counter number of repeats in a vector and store in a matrix with repeated value and amount of times repeated.
2 次查看(过去 30 天)
显示 更早的评论
Hi all,
So my problem is this: I have a vector of failure times. I need to go through this vector and find all the repeating times and count each time it's repeated and then write a matrix or two vectors of the same length with the failure time and how many times it occurred.
So, for example, let's say my failure times, x, looked like: x = [20;30;40;40;50;50;50;60;70]; what I want is to get something like this: y = [20 1; 30 1; 40 2; 50 3; 60 1; 70 1]; OR y = [20;30;40;50;60;70]; z = [1;1;2;3;1;1];
so that I can then proceed with failure forecasting and finding the expected failures now. Since I'm not sure what the data would look like, I'm not sure how to make an empty vector/matrix to hold the values unless I did it based on finding the amount of repeats:
repeatedVals = length(unique(x) < length(x));
which returns the amount of repeated values and then I could do an empty vector/matrix the length of N (total failure times) - repeatedVals...
Anyone have any ideas?
Thanks! E
0 个评论
采纳的回答
Walter Roberson
2017-7-12
x = [20;30;40;40;50;50;50;60;70];
[y, ~, uidx] = unique(x);
z = accumarray(uidx, 1);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 GPU Computing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!