Where is the error in getting this to recognize the relations?

I'm working on a code that requires a combing of a 1000 number array(nr), the numbers being random and all between 0 and 100. I've worked up this so far, but i can't get it to read them properly, nor give me an output.

clc %Clear console
load m05.mat %load given file

%% Initialization
satindices=[];
satvalues=[];

%% Processes
for i = numel(nr)
    if nr(2:end) == nr(1:end-1)
        satvalues=i;
    end
end

%% Output
fprintf("The indices of nr that satisfy the relations are %i\n",satindices)
fprintf("The values of the indices of nr that satisfy the relations are %i \n",satvalues)

Here's the actual prompt that came with the challenge: Write a program that will use for loop to find all the elements in vector nr that have the same value as the previous element of the same vector. Generate two result vectors: one with all indices of elements satisfying the condition, and another one with values of elements that satisfy the condition.



Read more here: https://stackoverflow.com/questions/66326422/where-is-the-error-in-getting-this-to-recognize-the-relations

Content Attribution

This content was originally published by BigD at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: