Hi,
I am consistently getting error while writing output in a CSV file using fprintf. I actually want to write my results in a CSV file. I have tried different lengths of the matrix and I get the same error even with 2 columns. Can anybody please help me understand what's the mistake here and how can I resolve this error?
Sample Code:
colname = {'col1' 'col2' 'col3'};fid = fopen('test.csv','w');fprintf(fid, '%s, %s, %s\n', colname{1:});for p=1:5% <some code>
fname = %reading image name from a directory
% <some code>
val1 = %calculating value1
val2 = %calculating value2
datacol = {fname val1 val2};fprintf(fid, '%s, %f, %f\n', datacol{p+1:});endfclose(fid);
Error: "??? Index exceeds matrix dimensions. at fprintf(fid, '%s, %f, %f\n', datacol{p+1:});"
P.S. writing "datacol = {fname val1 val2};" as "datacol = {fname,val1,val2};" brought the same error message.
Best Answer