フィルターのクリア

How to solve this only using looping

2 ビュー (過去 30 日間)
Yoga Arviansyah
Yoga Arviansyah 2018 年 9 月 24 日
コメント済み: Image Analyst 2018 年 9 月 24 日
For example A=(aa bb cc dd) and B=(aa bb xx yy zz) then i want to display like this (xx yy zz)
How to display like that by using looping only...??

採用された回答

Image Analyst
Image Analyst 2018 年 9 月 24 日
Try this:
A = [1,2,3,4]
B = [1,2,8,9,10]
lengthA = length(A);
lengthB = length(B);
maxLength = max([lengthA, lengthB])
for k = 1 : maxLength
if k <= lengthA && k <= lengthB
if A(k) ~= B(k)
fprintf('%.1f ', B(k));
end
elseif k > lengthA && k <= lengthB
fprintf('%.1f ', B(k));
elseif k <= lengthA && k > lengthB
fprintf('%.1f ', A(k));
end
end
fprintf('\n');
  2 件のコメント
Yoga Arviansyah
Yoga Arviansyah 2018 年 9 月 24 日
If the array is string what should i change ?? To make it work ??
Image Analyst
Image Analyst 2018 年 9 月 24 日
You'd need to convert the string to numbers with something like sscanf() or textscan(), or strsplit() along with str2double().

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

その他の回答 (1 件)

Bish Erbas
Bish Erbas 2018 年 9 月 24 日
編集済み: Bish Erbas 2018 年 9 月 24 日
One way of accomplishing this would be:
A = [1 2 3 4 8 9];
B = [1 2 3 4 5 6 7];
for k = 1:numel(A)
B(B==A(k))=[];
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by