How to read variables from one file in another file?

6 ビュー (過去 30 日間)
Lucius
Lucius 2015 年 5 月 22 日
回答済み: Lucius 2015 年 5 月 23 日
We have a file example.m with a variable abc=3.2. How can I load this variable abc from another file test.m in the same directory?
If I write in the test-file
example
abc
then I get in the workspace the error "At least one END is missing: the statement may begin here."
This is just an example. My problem is about reading an array from another file. Is this done the same as the solution above?

採用された回答

Lucius
Lucius 2015 年 5 月 23 日
I was lacking a
clear all; close all;
at the beginning. That was all and now it works

その他の回答 (1 件)

dpb
dpb 2015 年 5 月 22 日
Read the "Getting Started" tutorial of scripts and functions -- you pass arguments into functions and return results as return values. Any variable(s) which are to be exposed after a function completes must be in a return argument list to be available (or made global which is generally a_bad_idea (tm) from a code design standpoint.

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by