Import data from text file and use it on simulink

조회 수: 5 (최근 30일)
ni david
ni david 2011년 9월 6일
댓글: Amit Kumar 2022년 4월 16일
I have a txt file which has my signal versus time in two columns, how can i import it in simulink? I want to see the signal in simulink! thanks a lot in advance.
  댓글 수: 2
Paulo Silva
Paulo Silva 2011년 9월 6일
I changed your question title to something that better describes your question, the tags were also corrected.

댓글을 달려면 로그인하십시오.

답변 (3개)

Paulo Silva
Paulo Silva 2011년 9월 6일
%I don't have your data so I must create my own data
x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'wt');
fprintf(fid, '%6.2f %12.8f\n', y);
fclose(fid)
%Now I got the data file, import the data
fid = fopen('exp.txt', 'r');
a = fscanf(fid, '%g %g', [2 inf])
simin = a';
fclose(fid)
%Plot it just to see if it's correct, first column is time and second is data
plot(a(:,1),a(:,2))
Run the code to import your data and in your model insert one From Workspace block and all should work fine, be aware that data will be interpolated if your simulation runs from more than the time you have in your data, please check the From Workspace block configuration.

Grzegorz Knor
Grzegorz Knor 2011년 9월 6일

Ubedullah Saeed
Ubedullah Saeed 2015년 5월 3일
Does that method preserve the data import in simulink for multiple runtime of the model or its just one time process

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by