Generating data file in matlab

In summary: An example of input could be something like this:---> fread('test_io.dat', 1000);An example of output could be something like this:---> fwrite('test_io.dat', 'foo');
  • #1
balogun
14
0

Homework Statement



I have a retake in MATLAB and in my briefing they said i will have to generate a data file and analyse it.Can someone please tell me what a data file is and how you generate it.
I have used the help function in MATLAB but did not find it very useful .
Thanks in advance.

Homework Equations





The Attempt at a Solution


Used help function but not useful.
 
Physics news on Phys.org
  • #2
Your question is so hopelessly vague that no one here will be able to help you with it. MATLAB includes many functions that can be used to generate data sets, but you've given us absolutely no information on the kind of data you want. It also includes functions which can be used to write arrays out to files on the disk.

- Warren
 
  • #3
...

Sorry didn't know there were many different kinds of datafiles.I don't really know the type of datafile his going to give so i thought there should be some kind of general method.But from the last coursework i was given he asked for an ascii datafile.
 
  • #4
Is the data supposed to be a sound, or a picture, or a one-dimensional random signal? What's the distribution supposed to look like? What's the meaning of the data? Is it supposed to be one column in a text file or twelve? One point or ten billion points? Floating-point or fixed-point or integers?

You've given us no information at all about how to help you. It's as if you went into a library and told the librarian you were looking for "a book."

- Warren
 
  • #5
As chroot has mentioned, it would be helpful if you described an example.

A data file , as you have described it, is information that can be 'used by' (input) or 'generated by' (output) a computer program.

Since you want to generate a data file, you are interested in input/output syntax. That's true for any computer language, however for MATLAB it may begin with something like ---> FID_out=fopen('test_io.dat",'w');
Here's http://ocw.mit.edu/NR/rdonlyres/025D2855-5E98-42A6-A415-B408855187CE/0/tutorial05.pdf [Broken] that illustrates this concept.
 
Last edited by a moderator:

1. How do I generate a data file in Matlab?

To generate a data file in Matlab, you can use the save function. This function allows you to save variables from your workspace to a file in either .mat or .txt format. Simply specify the name of the file and the variables you want to save.

2. Can I generate a data file with specific formatting?

Yes, you can specify the format of the saved data file using the save function. For example, you can specify the precision of floating-point numbers or the delimiter between columns in a text file.

3. How can I generate a large amount of data in Matlab?

There are several ways to generate a large amount of data in Matlab. One option is to use the rand function to generate random numbers, which can then be saved to a data file. Another option is to use a loop to generate and save multiple sets of data.

4. Is there a way to automatically generate data files in Matlab?

Yes, you can use the fprintf function to automatically generate data files in Matlab. This function allows you to specify the format and content of the data file, and you can use loops to generate multiple sets of data.

5. How can I generate data in a specific range in Matlab?

To generate data in a specific range in Matlab, you can use the randi function. This function allows you to generate random integers within a specified range, which can then be saved to a data file. You can also use the linspace function to generate a specified number of equally spaced values within a range.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
341
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
684
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
940
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top