Question about using 'load' to load an .m file
古いコメントを表示
I'm currently trying to use the load command to pull data from an existing .m file I've downloaded from the internet, but the .m file is coming in as a [0x0] vector, and it shouldn't be.
I'm getting the message
"Attempted to access sampleDataFlow(:,1); index out of bounds because size(sampleDataFlow)=[0,0]."
when I attempt to define a variable to column 1. Any idea why this would be happening?
Thanks
回答 (3 件)
Ryan G
2012 年 9 月 14 日
0 投票
Although you can use the load command with an m-file, in my humble opinion, this would not be the ideal way to transfer data nor read data.
My suggestion would be to utilize the Import Tool available in the Home tab (R2012b). It's available in other versions but I like to be forward thinking.
This will allow you to utilize a GUI for the first time you import making it easy to determine if the data was imported correctly and easy to change the import method to achieve desired results. Once you're established the correct method you will be able to automatically generate a script or function to do it again and again.
The link above describes it better than I ever could.
9 件のコメント
Robert
2012 年 9 月 14 日
Robert
2012 年 9 月 14 日
Ryan G
2012 年 9 月 14 日
What are the first couple lines inside the file?
Say I create a MATLAB file, and put the contents as
1 2 3
4 5 6
save it as myfile.m, then use the command
x = load('myfile.m')
You will see it loads the data into x and displays this in the command window. Try this out first and make sure it works. It should load it like an ascii file I believe. What does the m-file look like when you open it? What type of data is inside?
Robert
2012 年 9 月 14 日
Ryan G
2012 年 9 月 14 日
The two things you say are kind of opposing each other. On the one hand you say it contains the data on the other you say when you open it it's empty. How do you know what data it contains if it's empty when you open it?
Robert
2012 年 9 月 14 日
Ryan G
2012 年 9 月 14 日
I would verify that hte data exists in the downloaded file. It sounds like the issue is coming up between downloading the file and the file that exists locally
Robert
2012 年 9 月 14 日
Walter Roberson
2012 年 9 月 14 日
0 投票
Try using the -ascii option when you load()
Azzi Abdelmalek
2012 年 9 月 14 日
編集済み: Azzi Abdelmalek
2012 年 9 月 14 日
you can get your data like you import any text file
fid = fopen('file.m');
line1 = fgetl(fid)
res=line1;
while ischar(line1)
line1 = fgetl(fid);
res =char(res,line1)
end
fclose(fid);
カテゴリ
ヘルプ センター および File Exchange で Downloads についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!