how to use the load-command

8 views (last 30 days)
tr206
tr206 on 23 Mar 2015
Commented: tr206 on 24 Mar 2015
Hi,
I am trying to upload my stock return data. The person who wrote the code told me that the data file is a Matlab data file and he applies the load-command to the data. I have my data in Excel and the xlsread-command does not do the trick as I do not get the data the way I want.
How can I use the load-command? As far as I understand, I must have a Matlab file to use this command but how can I create a Matlab file (.m format)??
I would be very grateful if someone could help me with that. I cannot find the solution in one of my books on Matlab.
Thanks in advance.
  1 Comment
tr206
tr206 on 24 Mar 2015
Hi, Thanks for your help. I made it the way you described using uiimport and dlmwrite. Now I get the message Error using load Unknown text on line number 1 of ASCII file C:\Users\tr206\Documents\MATLAB\stkmkt_ret_data "M".
Error in garchmidas_roll (line 39) load stkmkt_ret_data;
What am I doing wrong?
I have also imported the data as matrix, dataset etc. using the import tool in matlab. In this case I get the message that the function
ft_ind0=find( diff(daily_stk(:,2)) ~= 0 ) is not applicable.
Would it help if I sent you the code in addition to my dataset so that you can look into it?

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 23 Mar 2015
Your question is a bit lacking in details. Most likely, the code you're trying to run expects a .mat file (not an .m file which is for code) with certain variables. You would have to extract your excel file into variables with the same name and save that as a .mat file for it to work.
Your best course of action is to go back to the person who wrote the code and ask him/her how to generate the .mat file (or what variables of what type are supposed to be in it). A good lesson from this is to properly document code when you write it. Particularly, give a good explanation of inputs and outputs.
  3 Comments
Ilham Hardy
Ilham Hardy on 23 Mar 2015
Yes? --> No,
You 'read' the excel file using xlsread() command, arrange the data until you satisfied the above conditions, then save the workspace into matfile using save() command.
But maybe better if you use uiimport() command instead of xlsread() just to have more overview on the data format you're importing (ie. mm format)
Guillaume
Guillaume on 23 Mar 2015
Thorsten, yes the idea was to import the excel file, modify the data as appropriate and save it in the format that the code expects.
However, from the description you got, it looks like the code is expecting a text file rather than a .mat file. A .mat file is binary, it just contain variables and values, it does not have 'columns' or 'format'.
The idea is still the same. Import the excel file (with xlsread or uiimport), manipulate it to it fits the required format, and save it. For text files, use dlmwrite instead of save. Possibly, all this can be done in excel.
If you post of sample of the excel file, we may be able to help further.

Sign in to comment.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!