49 views (last 30 days)

njj1
on 8 Mar 2018

What do you mean by "similar"? If you want simply see the number of entries that are the same, then this could do the trick:

s = A==B; %this is a boolean vector that will be 1 if the entries are the same and 0 if different

similarity = sum(s)/numel(s); this is the number of entries that are equal divided by the total number of entries

njj1
on 8 Mar 2018

I'll try to answer your question as best I can understand it. I'm guessing that you have a for loop in which a variable that is being calculated, and you want to store those calculated variables into a vector for future analysis.

stored_variable = zeros(number_of_computations,1); %pre-allocate for speed

for i=1:number_of_computations

variable1 = i^2 + 2*i + 5; %compute your changing variable here

stored_variable(i) = variable1;

end

You can actually bypass the first computation and go directly to the stored variable like:

stored_variable = zeros(number_of_computations,1); %pre-allocate for speed

for i=1:number_of_computations

stored_variable(i) = i^2 + 2*i + 5; %compute your changing variable here and store it

end

If you have a more specific problem, I might be able to provide a better answer.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.