Why I have problem in my program.

2 ビュー (過去 30 日間)
Naoki Ishibashi
Naoki Ishibashi 2016 年 9 月 10 日
コメント済み: Star Strider 2016 年 9 月 11 日
I am getting the following error
Attempt to execute SCRIPT load as a function:
/Users/naoki/Documents/MATLAB/Add-Ons/TS2004.07/load.m
Error in load (line 17)
mydata{i,k} = load(filename);
And this is my programming:
numFiles = 31;
mydata = cell(31, 7);
for i = 1:numFiles
if i<10
daystr_j = ['0', num2str(i)];
else
daystr_j = num2str(i);
end
for k = 0:7
j = 3*k;
if j<10
daystr_j = ['0', num2str(j)];
else
daystr_j = num2str(j);
end
filename = ['TS2004.07.',daystr_i,'.',daystr_j,'00.txt'];
mydata{i,k} = load(filename);
end
end
I want to load all text datas, TS2004.07.01.0000.txt to TS2004.07.31.2100.txt.
Please give me any advice.
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 9 月 10 日
By the way:
daystr_i = sprintf('%02d', i);
saves you from having to test the value or add the leading '0' or do the num2str()

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2016 年 9 月 10 日
編集済み: Star Strider 2016 年 9 月 10 日
You have written a script called load.m:
/Users/naoki/Documents/MATLAB/Add-Ons/TS2004.07/load.m
That is preventing you from using the MATLAB core load function. This is called ‘overshadowing’, and is to be absolutely avoided.
The solution is to name your function something else, like ‘my_load.m’ or something even more descriptive of its function.
  3 件のコメント
Naoki Ishibashi
Naoki Ishibashi 2016 年 9 月 11 日
Thank you for answer. I tried, but I still have a same error.
Star Strider
Star Strider 2016 年 9 月 11 日
My pleasure.
Type this in your Command Window:
q = which('load', '-all')
When I run that, I get:
q =
'built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\general\load)'
'C:\Program Files\MATLAB\R2016a\toolbox\shared\reqmgt\+rmiml\@RmiMlData\RmiMlData.p'
'C:\Program Files\MATLAB\R2016a\toolbox\shared\reqmgt\+rmidata\@RmiData\RmiData.p'
'load is a Java method'
'load is a Java method'
'load is a Java method'
'C:\Program Files\MATLAB\R2016a\toolbox\matlab\winfun\@COM\load.m'
That is all you should get. If you get any other results, that will indicate where the problem is.

サインインしてコメントする。

その他の回答 (1 件)

James Ryan
James Ryan 2016 年 9 月 10 日
It could be a simple bug. You use daystr_i and daystr_j in the filename, but you never set daystr_i. It looks like you set daystr_j twice by accident. Actually it might be a good idea to use variable names which don't look so much alike.
Try that and respond if there's still a problem.
  1 件のコメント
Naoki Ishibashi
Naoki Ishibashi 2016 年 9 月 11 日
Thank you for answer. I tried but I still have same error.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by