MATLAB: Convert Matrix to specified format as a text file to be read in Xilinx

vhdl

Hi!, I have a 256X256 matrix. How do i convert these numbers into the text file format as specified to be used in Xilinx:
((1,25,4,6,8..256),(1,6,7,4,5,6,78...),...,(8,4,5,53,53,53,5,35))
Each bracket(..) contains 256 values of EACH ROW of 256X256 matrix.
Thank You!

Best Answer

Here is one way:
N = 256; % length of each row
X = reshape(1:N^2,N,N).'; % fake data
% define the text format of each row:
fmt = ['(%d',repmat(',%d',1,N-1),')'];
% write data to file:
fid = fopen('temp.txt','wt');
fprintf(fid,['(',fmt],X(1,:))
fprintf(fid,[',',fmt],X(2:end,:).')
fprintf(fid,')')
fclose(fid)