Index exceeds matrix dimensions

조회 수: 2 (최근 30일)
Andrei Creanga
Andrei Creanga 2019년 2월 11일
편집: Yogananda Jeppu 2019년 2월 15일
Hello,
I keep getting the error listed in the title when using simulink on matlab R2017a.
"index exceeds matrix dimensions".
I've tried reading the answers on here but any variation I make in my code or simulink doesn't resolve the problem.
Also, sometimes it'll run but other times it spits out this error.
my code is
a = 4;
b = 25;
c_vals = [200 20 10 2]
figure(1)
hold on
for i=1:length(c_vals)
c = c_vals(i);
sim('simulink1'); %% this is where the error occurs
simulink(i)=simulink1;
plot(simulink1)
end
hold off
legend(["-200","-20","-10","-2"]);
sim('simulink1');
  댓글 수: 2
Preethi
Preethi 2019년 2월 11일
hi,
Can you indicate on which line error appears?
Andrei Creanga
Andrei Creanga 2019년 2월 11일
Thank you for pointing that out I just fixed the question

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

답변 (2개)

Luna
Luna 2019년 2월 11일
편집: Luna 2019년 2월 11일
You can't use simulink as a variable name.
simulink(i)=simulink1; % simulink is already a built-in function which starts simulink
%% Use this:
mySimResult{i} = simulink1; % I don't know what kind of variable your simulink1, that's why I put cell array with curly braces.
  댓글 수: 2
Andrei Creanga
Andrei Creanga 2019년 2월 11일
Im doing a transfer function in simulink that will repeat with the four values shown in "c_vals=". yet even when I make c a single variable it gives me this error.
Luna
Luna 2019년 2월 12일
What is the name of your script .m file and .slx file?

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


Yogananda Jeppu
Yogananda Jeppu 2019년 2월 15일
편집: Yogananda Jeppu 2019년 2월 15일
As a rule please use meaningful variable names. Simulink is a keyword. I get a feeling you are trying to store that data variable "simulink1" from model named "simulink1" to a variable "simulink". Depending on what you have set for the simulation time the “to workspace” variable "simulink1" can be of same size or different size but it will have many data points based on time of simulation. That cannot be assigned to simulink(i). For your problem statement fix the simulation time and sampling time. This will give you a fixed length of simulink1 - output from model simulink1. use that to store. As you have c_vals of length 4 initialise SIMULINK (better than simulink) to zeros(1001,4) if you are using 10 seconds and 10 msec sampling. SIMULINK(:,i) = simulink1; should store the data for you.

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by