load() into workspace?

6 ビュー (過去 30 日間)
Knut
Knut 2011 年 9 月 8 日
If I place load() into a m-file script, it will load into the workspace, available for the caller.
If I place it into a m-file function, I will have to pass the variable names or nest out the struct.
Is there any way to pass load() into a function and pass whatever is in it directly into the workspace, without doing a lott of messy code?

採用された回答

Harry MacDowel
Harry MacDowel 2011 年 9 月 8 日
Why don't you use textread or textscan or fscanf?
doc textread
doc textscan
doc fscanf
You can control the type of variables and furthermore you can even read the data with different delimiters.
  2 件のコメント
Knut
Knut 2011 年 9 月 8 日
I am reading *.mat files, so those functions wont do it.
Knut
Knut 2011 年 9 月 8 日
Bah... How do I un-accept an answer?

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

その他の回答 (1 件)

Paulo Silva
Paulo Silva 2011 年 9 月 8 日
maybe
evalin('base', 'load(...')
  2 件のコメント
Knut
Knut 2011 年 9 月 9 日
This solved my problem. Thank you and sorry that I cannot set your post to "solved"
Jan
Jan 2011 年 9 月 9 日
It is very hard to debug problems, if you create variables in other workspaces by EVALIN. Imagine you have several such functions, which run in different orders. Then it is nearly impossible to find out, who is responsible for the final value. Therefore I recommend: Data = load() and export the Data struct as output. This is not clumsy and reduces the effort for debugging tremendously.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by