As i state in the title,i want to export a matrix from matlab to a .txt
, in format that is supported by c. What i mean is something like this {{1,2,3,4},{5,6,7,8}......}.
Any suggestions ?
Edit. I used this loop and it seems that it did the trick very nicely. Thanks for the help :)
for (row = 0;row < XLENGTH ; row )
{ for(collumn=0;collumn<YLENGTH;collumn )
{ fscanf(fr, "%d " ",", &num);
Image_input[row][collumn]=num;
}
}
CodePudding user response:
I think you should be able to use jsonencode() to turn a matrix into the same string format as you want albeit with [] instead of {}. You could then use regexprep() to replace the brackets and fprintf() to write to a file.
That said you could definitely write a function in c using fscanf() and use Matlab's writematrix as others suggested to do something far neater, and probably slightly faster as regexprep will add time.