MATLAB: How to solve this only using looping codeloopingMATLAB 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…?? Best Answer 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)); endendfprintf('\n'); Related SolutionsMATLAB: How to fprintf element in matrix using array without using loops Like thisA=randi([-5,5],2,2);B=randi([-10,10],3,4);K=kron(A,B);a=1:6;a2=1:8;[ag,a2g] = ndgrid(a,a2);fprintf('K(%.0f,%.0f) is %.1f\n',[ag(:).'; a2g(:).'; K(:).']) MATLAB: How to use fprintf to print strings and words A = {'a', 'b','c'}; % A nicer notationB = [1 2 3];Either a loop:for k = 1:length(A) fprintf('%s %g\n', A{k}, B(k));endOr create one cell at first:C = cat(1, A, num2cell(B));fprintf('%s %g\n', C{:}); Related QuestionHow to fix thisNested Loop Script (Triangle)I have a 67*1 matrix of 1’s and 0. I want that if variable = 1, it should display ‘good’ else ‘nothing’.
Best Answer