I have a .mat file with m x n values. For simplicity, let's say we have 2 rows and 3 columns as:

### 2 4 6

### 2 1 4

I want to be able to export these values from .mat file to a text file, however, in such a manner that each line has the respective row from the .mat file with values in each row separated by comma. For the above example, in the txt file, it should look like:

### 2,4,6

### 2,1,4

This is what I did till now:

```
gt1 = load('Benchmark\AAmpiidata\groundtruth.mat');
r = gt1.gTruth.LabelData{1,1}{1,1};
allOneString = sprintf('%.0f,', r(1,:));
allOneString = allOneString(1:end-1);% strip final comma
fid=fopen('allOneString.txt','w');
fprintf(fid,'%s',allOneString);
fclose(fid);true 

```

I am able to extract the first row from .mat file as I require. I get this:

```
492,304,78,220

```

However, I don't know how to extract multiple rows from .mat file. Any help will be appreciated!

P.S. In the above code, in the .mat file `gt1` directly doesn't have the values. The values I need (mxn) can be extracted using `gt1.gTruth.LabelData{1,1}{1,1}`