find missing elements in a matrix

3 ビュー (過去 30 日間)
Rashmil Dahanayake
Rashmil Dahanayake 2014 年 9 月 19 日
コメント済み: Rashmil Dahanayake 2014 年 9 月 23 日
Hi, I have a matrix represents code numbers.
A=[1 2 3 6 7 45 46 47 53 78 80];
B=[55.23 ,74.22]; % B is if same length of A, and contains element by element corresponding data
Say the numbers should be in the range 1:80.
How can I find the numbers which are missing in A.
eg in above case, the expected answer is missing=[4 5 8 9 ... 79]
Then to print a text file
experiment 1 results 55.23
experiment 2 results 442.23
experiment 4 data missing
.
.
experiment 79 data missing
experiment 80 results 442.2
  2 件のコメント
Stephen23
Stephen23 2014 年 9 月 19 日
編集済み: Stephen23 2014 年 9 月 19 日
Your edit added "Then print to a text file". This is:
  • A separate topic.
  • Easy to solve yourself using any search engine.
Other users here are not paid to write your code for you, but will happily help if there is something that needs explaining or clarification.
Rashmil Dahanayake
Rashmil Dahanayake 2014 年 9 月 23 日
^ non technical comment. Scroll down to read relevant answers.

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

採用された回答

Stephen23
Stephen23 2014 年 9 月 19 日
Try setxor :
setxor(A,1:80)
  2 件のコメント
Stephen23
Stephen23 2014 年 9 月 19 日
See also Fabio Freschi's answer using setdiff .
Rashmil Dahanayake
Rashmil Dahanayake 2014 年 9 月 20 日
see my updated answer incorporating Fabios

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

その他の回答 (2 件)

Fabio Freschi
Fabio Freschi 2014 年 9 月 19 日
Try this
A=[1 2 3 6 7 45 46 47 53 78 80];
all = 1:80;
missing = setdiff(all,A);
Fabio
  1 件のコメント
Rashmil Dahanayake
Rashmil Dahanayake 2014 年 9 月 19 日
this method also works

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


Rashmil Dahanayake
Rashmil Dahanayake 2014 年 9 月 19 日
編集済み: Rashmil Dahanayake 2014 年 9 月 19 日
Full Answer for my question asked previously. In case if someone might find it usefull
A=1:3:20; % in complete data
B=1:20; % Full index
missing = setdiff(B,A); % check for missing elements
A=strread(num2str(A),'%s')';
for ms=1:length(missing)
A=horzcat(A(1:(missing(ms)-1)),'misplaced results',A(missing(ms):end));
end
%A % verify answer

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by