# How to copy a vector from Matlab to Freefem

**URL:** https://community.freefem.org/t/how-to-copy-a-vector-from-matlab-to-freefem/267
**Category:** General Discussion
**Created:** [February 25, 2020, 4:24pm UTC](https://community.freefem.org/t/how-to-copy-a-vector-from-matlab-to-freefem/267 "2020-02-25T16:24:50Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![lietvo](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lietvo](https://community.freefem.org/u/lietvo)
#### Post date: [February 25, 2020, 4:24pm UTC](https://community.freefem.org/t/how-to-copy-a-vector-from-matlab-to-freefem/267/1 "2020-02-25T16:24:50Z")

</div>

Hello everyone,  
I want to copy a vector from Matlab which contains 1000 values to Freefem, I tried to read the manual book but I can’t see how to do it! I don’t want to do it by hand because it’s too much! So, how to do it?  
Thank you for any comments!

---

<div class="post-metadata">

### Author: ![henkel](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@henkel](https://community.freefem.org/u/henkel)
#### Post date: [February 26, 2020, 1:47pm UTC](https://community.freefem.org/t/how-to-copy-a-vector-from-matlab-to-freefem/267/2 "2020-02-26T13:47:17Z")

</div>

A blunt way to do this is to export the data from matlab as ascii, e.g. with `save vector.txt -ascii yourvector` and then read it in with FreeFem in the following way:

```
int nol = 1000; // length of your vector

real[int] data(nol);

ifstream file1("vector.txt");
for (int cnt = 0; cnt < nol; cnt++){
  file1 >> data(cnt);
}
```

---

<div class="post-metadata">

### Author: ![lietvo](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lietvo](https://community.freefem.org/u/lietvo)
#### Post date: [March 1, 2020, 6:19pm UTC](https://community.freefem.org/t/how-to-copy-a-vector-from-matlab-to-freefem/267/3 "2020-03-01T18:19:20Z")

</div>

Thank you very much! It works!
