Load function "unknown command option" while used in for loop+ while double clicking a file in matlab

10 ビュー (過去 30 日間)
Hello everyone! I am trying to write a script where I will perform analysis on a specific file in a saved workspace. I have multiple workspaces in one folder (with names differing), and I would like to loop over each workspace in my folder to do my analysis. I am using this code:
c=dir("*.mat");
filenames={c.name};
ul=numel(filenames);
for u= 1:ul
load(filenames{u})
However, I have an error saying
Error using load
Unknown command option.
I restarted MATLAB to be sure, and now when I try to open a workspace by double clicking on it, I get the same error.
Anyone knows why this happens?

回答 (1 件)

Stephen23
Stephen23 2018 年 8 月 23 日
編集済み: Stephen23 2018 年 8 月 23 日
"Anyone knows why this happens?"
Because the leading '-' character in the filename means that it is not a valid filename. Using a leading '-' is a syntax that indicates the start of an option, and is not valid for filenames: "File names must start with a letter, and can contain letters, digits, or underscores."
Note that save will not accept that name either. The reason for this is that .mat files, like function names, are closely tied up with the language syntax and MATLAB operation, and must follow the rules of the language.
  3 件のコメント
Dinc Yasat Hacibalogly
Dinc Yasat Hacibalogly 2018 年 8 月 23 日
Well, I have changed the filename to "e.mat" and I still get the same error.
Stephen23
Stephen23 2018 年 8 月 23 日
編集済み: Stephen23 2018 年 8 月 24 日
@Dinc Yasat Hacibalogly: please show us the output of this command:
which load -all
What MATLAB version are you using?

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by