- #1

Deathcrush

- 40

- 0

So imagine an equation that has two indexes, and that can be expressed as a matrix, how can I do something like this in Matlab? using a for cycle?

You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- Thread starter Deathcrush
- Start date

- #1

Deathcrush

- 40

- 0

So imagine an equation that has two indexes, and that can be expressed as a matrix, how can I do something like this in Matlab? using a for cycle?

- #2

Mark44

Mentor

- 36,311

- 8,281

Can you give us an example? What you've said is on the vague side.

- #3

Deathcrush

- 40

- 0

like for example, if I have I_{ij}=v_{i}/v_{j} considering that I know v for every i or j

- #4

Grep

- 298

- 2

So imagine an equation that has two indexes, and that can be expressed as a matrix, how can I do something like this in Matlab? using a for cycle?

Often unnecessary to use a for loop, but you can always do things like this:

Code:

```
a = [1 2 3; 4 5 6; 7 8 9];
for i = 1:3,
for j = 1:3,
a(i,j)
end
end
```

- #5

Deathcrush

- 40

- 0

- #6

Grep

- 298

- 2

I'm rusty on my MATLAB, but something like this perhaps?like for example, if I have I_{ij}=v_{i}/v_{j}considering that I know v for every i or j

Code:

```
for i = 1:length(v),
for j = 1:length(v),
r(i,j) = v(i)/v(j);
end
end
r
```

- #7

Deathcrush

- 40

- 0

oh thanks a lot Grep, that REALLY helped me, now I've finished :)

Share:

Comp Sci
Coding A Matlab Function

- Last Post

- Replies
- 7

- Views
- 70

- Last Post

- Replies
- 1

- Views
- 395

- Last Post

- Replies
- 10

- Views
- 321

Comp Sci
Matlab for loop indexing confusion

- Last Post

- Replies
- 1

- Views
- 369

- Last Post

- Replies
- 3

- Views
- 369

Comp Sci
Determining The Matlab Output

- Last Post

- Replies
- 1

- Views
- 35

- Last Post

- Replies
- 3

- Views
- 60

- Last Post

- Replies
- 3

- Views
- 1K

- Last Post

- Replies
- 6

- Views
- 739

- Last Post

- Replies
- 6

- Views
- 770