In an assignment A(I) = B, the number of elements in B and I must be the same.
Show older comments
Hi, I'm getting following error:
In an assignment A(I) = B, the number of elements in B and I must be the same.
... even though the number of elements are the same. I displayed their values and their number of elements to check this.
This is my code:
CS = 1;
STROOM = zeros(1,10);
STROOMB = zeros(1,10);
Counter = 0;
switch state
case STATE.READ % present state is READ
CS=0;
if (Counter ~= 10);
STROOMB(Counter+1) = Data_Out;
Counter = Counter+1;
next_state = STATE.READ;
This is the output:
(3) RUNNING TEST test
1
1
??? Error using ==> Model_run at 71
Error in 'Model_ADConverter/FSM_template/S-Function' while executing MATLAB S-function 'FSM_ADConverter', flag = 3 (output), at
time 0.0.
Caused by:
Error using ==> Model_run at 71
In an assignment A(I) = B, the number of elements in B and
I must be the same.
I've been looking hours for a solution (I'm pretty new to Matlab) but can't find it... Does anyone know the answer?
Thanks in advance!
Accepted Answer
More Answers (4)
Walter Roberson
on 29 Nov 2011
0 votes
What exactly is the size of Data_Out ?
the cyclist
on 29 Nov 2011
0 votes
Although you have shown us some code, it is too incomplete for us to run and try to reproduce the error. Can you post the smallest possible chunk of code that we would actually be able to run, to reproduce your error?
Are you familiar with breakpoints? You could try adding a breakpoint at the line that errors out, and look at the sizes.
Also, you could use a "try ... catch" structure around the line that gives the error, stopping the code in that way.
Robbe
on 29 Nov 2011
10 Comments
Walter Roberson
on 29 Nov 2011
You appear to have a try / catch / else / end structure, but "else" is not a defined control keyword for try / catch / end blocks.
Robbe
on 29 Nov 2011
Walter Roberson
on 29 Nov 2011
I think it was the cyclist that suggested adding try/catch .
Walter Roberson
on 29 Nov 2011
At the MATLAB prompt, give the command
dbstop in updateFSM
and then run again. It should stop in the debugger at the beginning of the routine.
Robbe
on 29 Nov 2011
Walter Roberson
on 29 Nov 2011
Must be a subfunction then. In that case, try clicking a breakpoint in to existence in updateFSM. Breakpoints do work when a script is called from another script.
Robbe
on 30 Nov 2011
Robbe
on 30 Nov 2011
Walter Roberson
on 30 Nov 2011
Sounds like you have a "clear all" in one of your scripts. "clear all" includes removing breakpoints.
Robbe
on 30 Nov 2011
Robbe
on 30 Nov 2011
0 votes
2 Comments
the cyclist
on 30 Nov 2011
I suggest that you start a new thread with this question, rather than burying it here. Also, consider "accepting" the answer here that you received that, if you found one critically helpful.
Robbe
on 30 Nov 2011
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!