Instead of converting the matrix into cells and adding an extra column with ‘N’ in it you can directly write the matrix to file with an ‘N’ at the beginning of each line as follows:
>> filename = 'nodedata.txt';
>> fid = fopen(filename, 'w');
>> B=transpose(Node_Matrix);
>> fprintf(fid, 'N,%d,%d,%d,%d\n', B(:));
>> fclose(fid);
In case you have large amounts of data in your “mat” file, you can load the matrix partially each time and append it to the text file.
>> my_file = matfile(‘example.mat’);
>> temp_data = m.Node_Matrix(1:100, :) %load first 100 rows
>> filename = 'nodedata.txt';
>> fid = fopen(filename, 'a'); %open the file in append mode
>> B=transpose(temp_data);
>> fprintf(fid, 'N,%d,%d,%d,%d\n', B(:));
>> fclose(fid);