I want to skip one step

Hi I have a matrix,I want the code to skip executing statements if the row is repeated. Thanks

2 件のコメント

the cyclist
the cyclist 2014 年 5 月 6 日
You are expecting us to guess too many details of what you are doing, which will likely lead to us wasting a lot of our time. Please provide a small example of the code you are using, where you want the skip to be inserted.
Geoff Hayes
Geoff Hayes 2014 年 5 月 6 日
yousef - please define what you mean by repeated. Do you mean that the current row repeats with a previous row in the matrix (so if you are considering row i then it is repeated if there is at least one row in the matrix from 1 to i-1 that is identical to row i? Or do you mean that row i is repeated in any row of the matrix from 1 to i-1 or i+1 to m (where m is the number of rows in your matrix).

サインインしてコメントする。

回答 (2 件)

yousef Yousef
yousef Yousef 2014 年 5 月 6 日

0 投票

Geof ,please have a look on this file. Thanks
Geoff Hayes
Geoff Hayes 2014 年 5 月 7 日
編集済み: Geoff Hayes 2014 年 5 月 7 日

0 投票

yousef - please remove/delete your answer (as it isn't an answer to your question). I've attached your pdf to this one.
From the document, your xx is shown as:
xx =
1 7 0 0
2 10 0 0
3 0 0 0
4 0 0 0
5 0 0 0
6 0 0 0
1 7 0 0
8 0 0 0
9 0 0 0
2 10 0 0
where any element in the first column represents an index (into ww) of the first occurrence of that value in ww. Here is your ww:
ww =
6 7 5 9 8 10 6 4 2 7
From the above, we see that x(1:6,1) are unique indicating that the first six values of ww are unique. The seventh value, xx(7,1), is 1, indicating that ww(7)==ww(1). x(8:9,1) are unique to any previous value in this first column, and xx(10,1) is 2, indicating that ww(10)==ww(2).
Thus if you are iterating over the first column in xx, you know if you have a repeated value in ww (not quite the row you mentioned above) if its index value, xx(i,1) is less than i:
[m,n] = size(xx);
for i=1:m
if xx(i,1)==i
% we have not encountered this number in ww before (i.e. ww(xx(i,1)) is unique thus far)
% so do stuff
else
% xx(i,1) is less than i, so we must have encountered this index in ww already
% do nothing
continue; % not needed, but just to be clear nothing happens here
end
end

5 件のコメント

yousef Yousef
yousef Yousef 2014 年 5 月 7 日
Thanks Geof for your help.It works well but still needs very small tricks to get the desired result. what about to make it more general ,the code will compare the hall rows to find out the row is repeated or not via this step x2=xx(i,:); out = ismember(xx,xx(i,:),'rows'); then use out Please check it out
Geoff Hayes
Geoff Hayes 2014 年 5 月 8 日
yousef - I don't understand what you mean by "hall rows". For sure if you think that what you propose might work, then by all means try it out! :)
yousef Yousef
yousef Yousef 2014 年 5 月 11 日
Thanks Geof,I really appreciate your contact with me,I want it to be in general form .
Your code is done based on comparing the first element of the row x(i,1)=i
what about if
xx=
1 2 3
4 5 6
1 2 3
3 2 4
1 2 3
3 2 1
1 3 2
Thanks
yousef Yousef
yousef Yousef 2014 年 5 月 11 日
Thanks Geof,I really appreciate your contact with me,I want it to be in general form .
Your code is done based on comparing the first element of the row x(i,1)=i
what about if
xx=
1 2 3
4 5 6
1 2 3
3 2 4
1 2 3
3 2 1
1 3 2
Thanks
yousef Yousef
yousef Yousef 2014 年 5 月 11 日
what about this one:
[~,~,A] = unique(xx,'rows','stable');
[n, bin] = histc(A, unique(A));
bin =
1
2
1
3
1
4
5
What do you think about it?Is there some thing better?
Thanks

サインインしてコメントする。

カテゴリ

製品

タグ

タグが未入力です。

質問済み:

2014 年 5 月 6 日

コメント済み:

2014 年 5 月 11 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by