How to iterate through an array to check for adjacent elements that are equal to one another using loops.
%This loads the file and allows us the work with the ‘nr’ varible
load("m05.mat")
%Varible for vector one. This vector will display all the indices of the
%elements meeting the condition
%V1 = nr;
%position one and position two in the array ‘nr’
p1 = sym(nr(:,1));
p2 = sym(nr(:,2));
%Varible for vector two. This vector will display all of the values of the
%elements that meet the condition
%V2 = nr;
%% Section 2: Processing
%Loop to find the values for V2
for i = 1:1:1000
if p1 == p2
disp(p1)
disp(p2)
end
p1 = sym(nr(:, +1)); %I want p1 and p2 to be reassinged to the next
%element in the array ‘nr’. ‘nr’ contains 1000 elements. I want the loop to
%check if adjacent elements in my loop are equal. For example if nr was
%equal to [1, 2, 2, 3], I would want it to display: ‘2’ ‘2’, at indices 2
%and 3.
p2 = sym(nr(:, +1));
end%This loads the file and allows us the work with the ‘nr’ varible
load("m05.mat")
%Varible for vector one. This vector will display all the indices of the
%elements meeting the condition
%V1 = nr;
%position one and position two in the array ‘nr’
p1 = sym(nr(:,1));
p2 = sym(nr(:,2));
%Varible for vector two. This vector will display all of the values of the
%elements that meet the condition
%V2 = nr;
%% Section 2: Processing
%Loop to find the values for V2
for i = 1:1:1000
if p1 == p2
disp(p1)
disp(p2)
end
p1 = sym(nr(:, +1)); %I want p1 and p2 to be reassinged to the next
%element in the array ‘nr’. ‘nr’ contains 1000 elements. I want the loop to
%check if adjacent elements in my loop are equal. For example if nr was
%equal to [1, 2, 2, 3], I would want it to display: ‘2’ ‘2’, at indices 2
%and 3.
p2 = sym(nr(:, +1));
end %This loads the file and allows us the work with the ‘nr’ varible
load("m05.mat")
%Varible for vector one. This vector will display all the indices of the
%elements meeting the condition
%V1 = nr;
%position one and position two in the array ‘nr’
p1 = sym(nr(:,1));
p2 = sym(nr(:,2));
%Varible for vector two. This vector will display all of the values of the
%elements that meet the condition
%V2 = nr;
%% Section 2: Processing
%Loop to find the values for V2
for i = 1:1:1000
if p1 == p2
disp(p1)
disp(p2)
end
p1 = sym(nr(:, +1)); %I want p1 and p2 to be reassinged to the next
%element in the array ‘nr’. ‘nr’ contains 1000 elements. I want the loop to
%check if adjacent elements in my loop are equal. For example if nr was
%equal to [1, 2, 2, 3], I would want it to display: ‘2’ ‘2’, at indices 2
%and 3.
p2 = sym(nr(:, +1));
end array MATLAB Answers — New Questions