how to use the load-command

조회 수: 6 (최근 30일)
tr206
tr206 2015년 3월 23일
댓글: tr206 2015년 3월 24일
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
tr206
tr206 2015년 3월 24일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2015년 3월 23일
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
Ilham Hardy
Ilham Hardy 2015년 3월 23일
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 2015년 3월 23일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by