0

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.

2
  • Use xlswrite, ask if you have any problems. Commented Mar 18, 2015 at 5:28
  • I tried using it but I can't figure out how, first problem was although I specified it as .xls it saved it as csv Commented Mar 18, 2015 at 6:13

1 Answer 1

2
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

Sign up to request clarification or add additional context in comments.

4 Comments

I've tried this results={'a';'b';'c';'d';'e'}; save('/home/user1/results.xls', results, '-ASCII') but it didn't work and gave this error Argument must contain a string.
i think you don't have to write the whole path, try something like save('results.xls', 'here you have the variable name1', 'var name2', '-ASCII')
according to your task, you might try: save('results.xls', 'a_res', 'b_res', 'c_res', 'd_res', 'e_res', '-ASCII') and you must find a results.xls file in your current directory of matlab. I tried for myself, for random values of those a_res, b_res, etc and it worked.
I've tried this save( 'results.xls','a_res', 'b_res', 'c_res', 'd_res', 'e_res', '-ASCII')) where a_res,...e_res are variables, but it doesn't save them properly, like the first three columns are empty then the fourth one has the first 5 cells filled with weird numbers then another two empty columns then 4 cells of weird numbers then another two empty columns then two cells with weird numbers then empty cell then another cell with weird number. Will update my question with a screenshot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.