FurtiveFelon
FurtiveFelon

Reputation: 15166

how best to loop through an array taking into account of the index in matlab?

I've seen this thread talking about map: Map function in MATLAB?

As a result, I was wondering whether there are similar ways to do it taking into consideration of the indices. Such as if i want to do something like (x_i)^i.

thanks a lot!

Upvotes: 3

Views: 149

Answers (1)

Amro
Amro

Reputation: 124563

An example:

>> x = randi(10, [1 5])
x =
     9     7     4    10     1

>> x.^(1:numel(x))
ans =
    9      49    64   10000  1

Upvotes: 4

Related Questions