want to save data from simulink, but receive "The file name is invalid because it does not have the extension ".mdl" or".slx"."

조회 수: 7 (최근 30일)
error:The file name 'C:\Users\Jason\Desktop\fangbo.xlsx' is invalid because it does not have the extension ".mdl" or".slx".
my code:
[t_time,x_state,y_out]=sim('C:\Users\Jason\Desktop\fangbo.xlsx',[0,181]);
filename_time='C:\Users\Jason\Desktop\fangbo.xlsx';
sheet=sheet1’;
position=A1’;
xlsxwrite('C:\Users\Jason\Desktop\fangbo.xlsx',Out1,sheet,B);
what's wrong with my code?how to solve this problem?
HELP!
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2024년 3월 6일
as matlab tells you, it's the wrong file extension :
[t_time,x_state,y_out]=sim('C:\Users\Jason\Desktop\fangbo.xlsx',[0,181]);
should be
[t_time,x_state,y_out]=sim('C:\Users\Jason\Desktop\fangbo.mdl',[0,181]);
or
[t_time,x_state,y_out]=sim('C:\Users\Jason\Desktop\fangbo.slx',[0,181]);
Mathieu NOE
Mathieu NOE 2024년 3월 6일
you should also probably use another file name for saving your data in the excel file - using the same name for simulink and excel is prone to confusion

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

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2024년 3월 6일
sim() runs a Simulink simulation. Model name should be *.slx or *.mdl, not *.xlsx.
Variable 'Out1' and 'B' are not defined in your xlswrite() line, not xlsxwrite().
Pay attention to the calling syntax of sim() and xlswrite(). Look at the document for examples.

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by