Search code examples
matlabfilefile-ioexport-to-excel

save Matlab data in a .xls file


I want to save data in a results.xls file which I want to set its first row "header" with a specific names lets say a,b,c,d,e. So, basically I have matlab function func1 which loops n times. In this loop, I call another function func2, where I do some processes and save save variables lets say a_res,b_res, c_res,d_res,e_res, I want to save those variables in each iteration in the results.xls file, where if the loop has 10 iterations then this means the results file will have 10 rows and 5 columns + the header row, so 11 in total. Could anyone please advise how this can be done in Matlab?

the below image shows the desired output where the first row is headings, then each row after that will be filled with variables calculated in each iteration of the loop.

enter image description here

EDIT:

Following the proposed solution, I used this:

save('results.xls', 'name','number_of_points','blood_level','width','sugval', '-ASCII');

where 'name','number_of_points','blood_level','width','sugval', are variables holding strings. But when I open the excel file this is what I get results.xls if anyone could please advise.


Solution

  • p = rand(1, 10);
    q = ones(10);
    save('test.xls', 'p', 'q', '-ASCII')
    

    This works for me. It saves me on the first row the random values of "p" and beneath I have the values for "q". You might check it out. Hope it helps