How to solve this only using looping
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yoga Arviansyah
le 24 Sep 2018
Commenté : Image Analyst
le 24 Sep 2018
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...??
0 commentaires
Réponse acceptée
Image Analyst
le 24 Sep 2018
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 commentaires
Image Analyst
le 24 Sep 2018
You'd need to convert the string to numbers with something like sscanf() or textscan(), or strsplit() along with str2double().
Plus de réponses (1)
Bish Erbas
le 24 Sep 2018
Modifié(e) : Bish Erbas
le 24 Sep 2018
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
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!