load() into workspace?

조회 수: 3 (최근 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 CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by