Writing results to different files

Hi,
I am trying to make a code so that when I run my function, the results get saved in different files each time I run it. So for example, I run my code the first time, the results get saved in file 1 then file 2, file 3... so on Is there a way I can accomplish this?

Risposte (1)

Stephen23
Stephen23 il 9 Nov 2015
Modificato: Stephen23 il 9 Nov 2015

2 voti

This is such a common question that we have a very detailed description in the wiki page, complete with example code. It has also be answered many times on this forum:
There are several different functions for saving data to text files. Picking the best one depends on the nature of your data, which you do not tell us anything about. You can find a list of these functions here:

3 Commenti

Tab for Lab
Tab for Lab il 9 Nov 2015
Modificato: Tab for Lab il 9 Nov 2015
I get that the sequence I require is:
function [ ] = multiruns(x, y, z)
for i = 1:6;
textFilename = ['file', num2str(k), '.txt'];
end
The problem now is I dont know how to input results in it. For example: x, y, and z are my results. How do I add those to the files in sequence?
Stephen23
Stephen23 il 9 Nov 2015
Modificato: Stephen23 il 9 Nov 2015
You have not told us what x, y, and z are: are they numeric arrays, cell arrays of steings, tables, character arrays, mixed cell arrays, ...? Are they scalar, 2D, or ND arrays? Each of these requires a different approach to file writing. If you want to tell us exactly what they are, then er can help you to write them to file.
You also need to tell us the required file format, which you have not told us so far.
The file format I want to make is either a text file or a mat file. If I want to read the files later I believe its best that we make it a .mat file. In terms of x, y, z results I thought by default I was making them scalar quantities. Basically x, y, and z are means of certain data that I have in my main function.
The question is to first run the experiment about 3 times, and add results (mean) to a different file each time. And once I have that file I need to be able to read it in order to graph the different means every time.
so for example: x = mean (data_a) y = mean(data_b) z = mean(data_c) Now I want all 3 of these results in a different file each time I run my main function. Then I want to read those files in order to graph these 3 means. How can I do that?

Accedi per commentare.

Categorie

Scopri di più su Environment and Settings in Centro assistenza e File Exchange

Richiesto:

il 9 Nov 2015

Commentato:

il 9 Nov 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by