How to read a variable whose suffix changes randomly?

Hi,everyone!
I have met a problem when ran a M program.
For example,running the program will product a variable as 'a_1'.And the number '1' is random.
Now,I want to get the value of 'a_number' and apply to myself M program.
How to do?
Thanks.

4 件のコメント

madhan ravi
madhan ravi 2018 年 8 月 24 日
Upload your code.
MT_jsmith
MT_jsmith 2018 年 8 月 24 日
編集済み: Walter Roberson 2018 年 8 月 24 日
clear;
clc;
time_1=0;
time_2=0;
time_3=0;
mdfimport()%It is M.file and products two signals: P01_Line_*and time_*.
% * is a random number
pause
if time_1~=0
linet=time_1;
pn=1;
elseif time_2~=0;
linet=time_2;
pn=2;
elseif time_3~=0
linet=time_3;
pn=3;
end
p11=sprintf('P01_Line_%d',pn);
P01=exist(p11);
if P01==1
linep0=eval(p11);
end
MT_jsmith
MT_jsmith 2018 年 8 月 24 日
If I need to deal with different signals,using mdfimport will product many variables . Is there a better way?
Stephen23
Stephen23 2018 年 8 月 24 日
編集済み: Stephen23 2019 年 3 月 15 日
@MT_jsmith: if you are using this FEX submission, then no, there is no better way because unfortunately the author made some bad design decisions, and instead of simply returning a structure they make all of the variables magically appear in the workspace. Basically their bad design decision forces you to write bad code.
However there is a simple solution: download this much better designed tool:
which lets you simply load into an output variable (a cell array):
data = importMDF3(...)
Note that the MATLAB Vehicle Network toolbox also supports reading MDF files:

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

 採用された回答

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Import and Analysis についてさらに検索

質問済み:

2018 年 8 月 24 日

編集済み:

2019 年 3 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by